开发者

Reset action cache from rake task

Is there any way of开发者_运维问答 reseting an action cache using a rake task?

I've an action inside my controller that shows the top 100 songs. I only need to generate the view once every 24h hours.


Here is my solution.

Controller

helper_method :custom_cache_path

before_filter only: [:method] do
  if params[:reset_cache]
    expire_fragment(custom_cache_path)
  end
end

def custom_cache_path
  "#{params[:id].to_i}-#{params[:controller]}-#{params[:action]}"
end

Rest request

RestClient.get "http://example.com/controller/method?reset_cache=1"
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜