Set custom cache_key of Fragment Caching

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Set custom cache_key of Fragment Caching

SeongHoon Ryu

I want to cache with custom cache_key of Fragment Caching because I don't want to change updated_at.


So, I googled and found monkeypatch(https://gist.github.com/tispratik/9276110). But It just a monkey patch.


Is there a way to set custom cache_key?

Thanks


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9452efd8-dcfe-4d1e-8451-8b45b491871d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Set custom cache_key of Fragment Caching

Steve-2
In Rails 5, you can turn cache versioning on and override #cache_version in your model if you'd like to return a different column.

https://github.com/rails/rails/blob/b2eb1d1c55a59fee1e6c4cba7030d8ceb524267c/activerecord/lib/active_record/integration.rb

In earlier versions of Rails, you can pass different column names to #cache_key, e.g., model.cache_key(:last_modified).

In either case, you can probably just override #cache_key in the model.

On Saturday, September 1, 2018 at 12:38:53 PM UTC-5, SeongHoon Ryu wrote:

I want to cache with custom cache_key of Fragment Caching because I don't want to change updated_at.


So, I googled and found monkeypatch(<a href="https://gist.github.com/tispratik/9276110" style="color:rgb(3,102,214);background-color:transparent" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Ftispratik%2F9276110\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAfWRzWLUV8idRwEudy0InfdDSNg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgist.github.com%2Ftispratik%2F9276110\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHAfWRzWLUV8idRwEudy0InfdDSNg&#39;;return true;">https://gist.github.com/tispratik/9276110). But It just a monkey patch.


Is there a way to set custom cache_key?

Thanks


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ad662458-cfc1-4363-9e03-0b27d81c4943%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.