Rails 关于 Fragment Caching

hxh1246996371 · May 06, 2015 · Last by jasontang168 replied at May 07, 2015 · 2247 hits

我想在项目里面用 Fragment Caching,于是就在 view 里面写了一句

-cache @dmeo do
    h1 hello wold

但奇怪的是我没有在 /tmp/cache 下面找到相应的缓存文件,而在后台通过 Rails.cache 写入的缓存是能找到的对应的缓存文件的。测试环境下默认的缓存是走的文件缓存,不知道是不是我用的不对

开发环境得需要 config/environments/development.rb 里面启用 perform_caching 才能让 Fragment Caching 启动的。

config/environments/development.rb

config.action_controller.perform_caching = true

#1 楼 @huacnlee 这样设置了,还是没找到缓存文件,不知道有没有缓存上

有文件的,views 的里 cache 会默认加 views 前缀,tmp/cache 里搜索下 find -name "views*"

在 cache_store 里应用原理是一样的,在 key 值也会生 views 前缀

#4 楼 @xxqfamous 奇怪了,一直找不到,估计是 Fragment Caching 没有起作用

看 log 里是否有 Cache digest 或 Read fragment 字样 就能判断缓存是否生效了。

重启试试

You need to Sign in before reply, if you don't have an account, please Sign up first.