开发者

Reset action cache from rake task

开发者 https://www.devze.com 2023-02-24 06:18 出处:网络
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.

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

精彩评论

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