Rails: How to Expire Fragments with stale assets

344 views Asked by At

I am using rails fragment caching and inside the fragment there is an image file. If i do a deploy (clearing the assets) with an updated image, the image digest fingerprint will change. So until the fragment expires it will be pointing to the old image and be broken. How can I expire the fragment to get the updated image (by the way I can't run rails cache clear)?

1

There are 1 answers

2
JTG On

According to the Rails Cache Guide, You can expire a fragment

expire_fragment(controller: 'products', action: 'recent', action_suffix: 'all_products')

You can even name your cache segment, ie

<% cache('some_image') do %>
  *Your code here*
<% end %>

And then expire it by that name

expire_fragment('some_image')