2011-06-16 60 views
0

我使用Devise在嚴重依賴於高速緩存的模型上進行身份驗證。由於登錄和註銷更新語句,此模型的緩存清理程序在每次登錄/註銷時都會被調用。在Rails中過濾清理器調用

有沒有辦法來過濾清掃回撥的起源?

回答

1

我試圖跳過清掃是這樣的:

class ModelSweeper < ActionController::Caching::Sweeper 

    def after_update(model) 
     unless model.current_sign_in_at_changed? or model.last_sign_in_at_changed? 
     expire_cache_for(model) 
     end 
    end 

    private 
    def expire_cache_for(model) 
    #some expire cache code 
    end 

end 

的current_sign_in_at和last_sign_in_at是由色器件sign_in和SIGN_OUT期間更新的兩個字段。這段代碼明顯假設你沒有自己的應用程序邏輯來更新這些字段,而只是設計更新它們。