1.ActionController::Base.new.expire_fragment(key)
2.ActionController::Base.new.fragment_cache_key(key)这个方法可以获得cache helper的生成的key。
比如
<% cache [article, 'metainfo'], :expires_in => 15.minutes do %>
<% end %>
这样会在memcache中(如果你也用memcache的话)生成的key为:
ActionController::Base.new.fragment_cache_key([Article.find(
1506783),'metainfo'])
=> "views/articles/
1506783 -20120917103126/metainfo"
3. caches_action :index, :cache_path => Proc.new {|controller|
{:controller => 'comments', :action => 'index', :article_id => controller.params[:article_id]}
}
这样生成的key为
Rails.cache.read("views/baozoumanhua.com/articles/1515325/comments",:raw=>true)可以读到这个action的缓存内容
4. caches_action :index, :cache_path => Proc.new {|controller|
{:controller => 'comments', :action => 'index', :article_id => controller.params[:article_id],:only_path=>true}
}
这样生成的key为
Rails.cache.read("views//articles/1515325/comments",:raw=>true)可以读到这个action的缓存内容