caches_action、:expires_in=>動的に設定します
-
15-11-2019 - |
質問
私が見たcaches_action
のすべての例:
caches_action, :expires_in => 5.minutes
.
しかし、アクションで使用されているオブジェクトの有効期限に基づいてexpires_in
を設定します。問題のオブジェクトがActionに送信されたexpires_in
に基づいているため、そのオブジェクトを参照する方法はありますか?
私はを使ってみました
caches_action, :expires_in => Object.find(params[:id])
.
しかし、AlAsそれは私にパラメータを参照しません。提案歓迎!
解決
Looks like you need to use a Proc which can get passed the params of the controller. Here is an example
caches_action :show, cache_path: Proc.new {|controller_instance| "some_cache_path_that_is_uniq/#{controller_instance.params[:id]}"}
他のヒント
The main point of action caching is to prevent actions being run every time a new request is coming in. Unless defined explicitly params are not taken into consideration.
If you want to cache based on instances I would suggest doing Conditional Gets.
所属していません StackOverflow