質問

私が見た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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top