I have the following in my users.html.slim view:
.header
Welcome
- cache ['user/details', user.last_modified] do
= render 'user/details', user: @user
My problem is that I have changed the user/details
markup, and since the users haven't actually changed I still get the cached version.
According to the docs, since the HTML has changed, the cache should expire
Cache fragments will also be expired when the view fragment changes (e.g., the HTML in the view changes). The string of characters at the end of the key is a template tree digest. It is an MD5 hash computed based on the contents of the view fragment you are caching. If you change the view fragment, the MD5 hash will change, expiring the existing file.
But that doesn't seem to be the case.
What is the proper way of solving this scenario? Where the parameters that you rely on the keys haven't changed, but the actual markup has changed. I am thinking on doing something like:
- cache ['user/details/v2', user.last_modified] do
= render 'user/details', user: @user
But I am wondering if that's what is more appropriate in these scenarios.
Instead of
user.last_modified
just passuser
.This will create a cache key based on the
user.id
anduser.updated_at
.If
last_modified
is in fact the thing that you want to be the cache key, you reference@user
but your cache key isuser
.