Search code examples
rubyruby-on-rails-4cachingspreerabl

How to decide objects passed to generate cache-key in rabl rails 4


We use rabl for our view templates with rails 4. Recently we are experimenting with caching these rabl views. We know that caching is done by adding following line to the views - cache some_object

My question is how to decide this some_object ?

For example We have a view that returns videos, that has associated products' info in it. Now there is data that is derived from a user object in this view that is not to be cached as caching that would result in incorrect data for requests from different users. So I understand that I need to pass the user object for the cache key. But what other objects should i pass to generate cache key for this view and get best performance?


Solution

  • It's depends what you have on view. If You have user and video i will add user and video to cache key. It all depends what is important for you. More objects in cache key means more often changes in cache because key will change when you change user and video.