这段代码的目的是什么。我在lib/act_as_audited/audit_spenper.rb下的audited-1.1.1插件中找到它
class AuditSweeper < ActionController::Caching::Sweeper #:nodoc:
def before_create(audit)
audit.user ||= current_user
end
def current_user
controller.send :current_user if controller.respond_to?(:current_user, true)
end
end
ActionController::Base.class_eval do
extend CollectiveIdea::ActionController::Audited
cache_sweeper :audit_sweeper
end
Audit.add_observer(AuditSweeper.instance)cache_sweeper是做什么用的?
发布于 2015-02-10 16:52:22
cache_sweeper负责在任何对象更改时使缓存过期。例如,如果您缓存了一个用户的配置文件,假设您更新了该用户的配置文件,那么旧的缓存应该过期,并且应该执行新的写操作。有关更多详细信息,请访问APIDock:
http://apidock.com/rails/ActionController/Caching/Sweeping
编辑:
这就像我们在expires_in中定义的时间,它应该在这么长的时间内过期。您可以在此处指定需要过期的操作,如edit, update, destroy。
https://stackoverflow.com/questions/28426141
复制相似问题