语言环境更改时如何使片段缓存过期? [英] How to expire fragment cache when locale changes?

查看:71
本文介绍了语言环境更改时如何使片段缓存过期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用片段缓存在使用I18n的Ruby on Rails站点上缓存页脚和导航栏。问题是,更改语言后将以错误的语言向您显示页脚和导航栏。当区域设置更改时,如何使片段缓存过期?

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.

这篇关于语言环境更改时如何使片段缓存过期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆