Rails 3 fragment caching not doing anything
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.
精彩评论