bte*_*les 4 ruby caching ruby-on-rails sweeper actioncontroller
我有一个扫地机应该到期一些动作缓存.即使调试器在调用expire_action之前立即停止,它实际上并没有使操作到期.知道会发生什么吗?
这是相关的清扫车和控制器.
#company_sweeper.rb(在'models'目录中)
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
Run Code Online (Sandbox Code Playgroud)
#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
Run Code Online (Sandbox Code Playgroud)
我知道它没有到期的方式是完整的报告返回旧数据,并几乎立即响应.很奇怪,对吗?
您cache_sweeper在CompaniesController中也有声明吗?清扫器必须包含在控制器中,该控制器对相关模型执行生命周期操作.除非您在ReportsController中使用Company实例执行操作,否则该cache_sweeper行不属于那里.
操作缓存包括隐式主机名.如果两个匹配命令在不同的主机名上进入,则缓存在一个下进行,在另一个下进行到期.