开发者

Rails 3 fragment caching not doing anything

开发者 https://www.devze.com 2023-04-10 11:30 出处:网络
Trying to get fragment caching to work in Rails 3.0.9. I have set this in development.rb: config.action_controller.perform_caching = true

Trying to get fragment caching to work in Rails 3.0.9.

I have set this in development.rb:

config.action_controller.perform_caching = true

And restarted the server 开发者_运维知识库(webrick). Then set this in my view:

<% cache("tags_json") do %>
    [Content to be cached]
<% end %>

And when I reload the page, I don't see anything in the log about caching. Reload the page again, same results, no cache has been written or read. There is also no cache files created anywhere in the file tree as far as I can tell.

I am new to caching so I am sure that I've just forgotten to set something up. Any help is appreciated, thanks!


Beside configuring ActionController's cache performing, you also need to set cache store in general config. Put

config.cache_store = xyz,abc

cache_store configures which cache store to use for Rails caching. Options include one of the symbols :memory_store, :file_store, :mem_cache_store, or an object that implements the cache API.

It defaults to :file_store if the directory tmp/cache exists, and to :memory_store otherwise. I'll recommend to use dalli store in-conjunction with memcached client.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号