2011-06-16 55 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期间更新的两个字段。这段代码明显假设你没有自己的应用程序逻辑来更新这些字段,而只是设计更新它们。