Using fragment cache digest to cache data. Issue I face is that when the db records changes cache key should be regenerate but it not refreshing and showing the old data.
I get data in json format.
cache "home_index_makes_listing_12_grid",:expires_in => 24.hours do
yield
end
while when I change or add any new html elements then digest key changes and cache refresh. but changes from backend not changes anything.
How to fix that issue?
Cache key doesn't automagically change when the record gets updated in the DB. There is no way for cache to somehow KNOW that the values in DB have changed.
Let's consider the below example to understand how cache key gets updated:
The key gets updated whenever the
userobject gets updated. How it works:Notice that the dynamic part in our key are
user.idanduser.updated_at. So, the key gets updated (and cache gets busted) only whenupdated_atof this particular user is changed.When the user requests this page (via browser or anything else), Rails tries to render this code fragment.
config.cache_store. For development env, it is usually set tofile(saved in /tmp). For production, you should use some caching server like Redis or Memcached.Hope this helps.