How can the cache for the views with translations be invalidated?

我的未来我决定 提交于 2019-12-03 21:52:55

Say, in your ApplicationController create the following class-method (or in a lib and extend by it):

def self.i18n_digest(*scopes)
    Digest::MD5.hexdigest I18n.t(scopes).to_s
end

Then you can use :cache_path option in your caches_action this way:

caches_action :some_action, cache_path: { some_key: i18n_digest('some', 'foo') }

Just make sure that you set the locale in a before_filter before this statement.

Docs on cache_path.

Note: I'm using the scope of translation ('some') to get all its nested messages as a hash.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!