我有一个清扫器,它应该会过期一些 Action 缓存。即使调试器在调用 expire_action 之前立即停止,它实际上并没有使操作过期。知道会发生什么吗?
这里是相关的清扫器和 Controller 。
#company_sweeper.rb(在“模型”目录中)
class CompanySweeper < ActionController::Caching::Sweeper
observe Company
def after_save(company)
expire_cache(company) if company.final_save && company.valid?
end
def expire_cache(company)
debugger <= #debugger stops here!
right before the call
I'm trying to make.
expire_action :controller => 'reports',
:action => 'full_report'
end
end
#reports_controller.rb
class ReportsController < ApplicationController
layout false
caches_action :full_report, :supplier_list, :service_categories
cache_sweeper :company_sweeper
def full_report
#do stuff...
end
end
我知道它不会过期的方式是完整的报告返回旧数据,并且几乎是即时响应。很奇怪,对吧?
最佳答案
您的 CompaniesController 中是否也有一个 cache_sweeper
声明?清扫器必须包含在对相关模型执行生命周期操作的 Controller 中。除非您对 ReportsController 中的 Company 实例进行操作,否则 cache_sweeper
行不属于那里。
Action 缓存包括一个隐含的主机名。如果两次命中来自不同的主机名,则缓存在一个下完成,过期在另一个下完成。
关于ruby-on-rails - Action 缓存未正确过期,即使我可以看到它正在被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2247410/