I'm trying to use fragment cache to cache the footer and navigation bar on a Ruby on Rails Site that uses I18n. The problem is, changing the language then shows you the footer and navigation bar in the wrong language. How do you go about expiring fragment cache when locale changes?
Rather than expiring the fragment cache, you should make the locale part of the cache key, i.e. something like
cache :locale => I18n.locale, ... do
...
end
This way different users can see different language versions of the footer/navigation bar but all will see cached versions.
When caching a fragment in Rails 3, this did the trick for me:
- cache([object, locale: I18n.locale]) do
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With