以下のコードからわかるように。アクションをキャッシュしていshow
ます。show action には次のメソッドもありますView.create_for(@song)
。
View.create_for(@song)
が呼び出されると、それぞれのキャッシュがクリアされるようにしたいと思います。
これについてどうすればいいですか?View
モデルでレール スイーパーを手動で呼び出す必要がありますか? もしそうなら、どのように?
私のコントローラー:
class SongsController < ApplicationController
caches_action :show, :cache_path => (proc do
song_path(params[:id], :user_id => user_signed_in? ? current_user.id : nil)
end)
# I tried with the following line, but this is not what I want. I only want to call the sweeper when `View.create_for(@song)` is called:
# cache_sweeper :views_sweeper, :only => [:show]
def show
@song = Song.find(params[:id])
View.create_for(@song)
end
end
マイスイーパー:
class SongsSweeper < ActionController::Caching::Sweeper
observe Song
def after_save(song)
expire_fragment(/songs\/#{song.id}\/.*?/)
end
end