首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rails中的cache_sweeper函数

rails中的cache_sweeper函数
EN

Stack Overflow用户
提问于 2015-02-10 15:21:17
回答 1查看 233关注 0票数 0

这段代码的目的是什么。我在lib/act_as_audited/audit_spenper.rb下的audited-1.1.1插件中找到它

代码语言:javascript
复制
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是做什么用的?

EN

回答 1

Stack Overflow用户

发布于 2015-02-10 16:52:22

cache_sweeper负责在任何对象更改时使缓存过期。例如,如果您缓存了一个用户的配置文件,假设您更新了该用户的配置文件,那么旧的缓存应该过期,并且应该执行新的写操作。有关更多详细信息,请访问APIDock:

http://apidock.com/rails/ActionController/Caching/Sweeping

编辑:

这就像我们在expires_in中定义的时间,它应该在这么长的时间内过期。您可以在此处指定需要过期的操作,如edit, update, destroy

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28426141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档