0
下記のコードから分かるように私はshow
アクションをキャッシュしています。私はまた、ショーアクション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