2
我expire_index
下面的方法获取调用,我看到了puts
在日志中。但是,当我刷新页面是陈旧的版本。
说明:我正在使用rails_admin更新模型。但也注意到直接使用rails控制台的相同行为。
感谢您的帮助。非常感激!
细节
app/controllers/posts_controller.rb
class PostsController < ApplicationController
caches_action :index
cache_sweeper :post_sweeper
def index
@posts = Post.published
end
def show
@post = Post.find(params[:id])
end
end
app/sweepers/post_sweeper.rb
class PostSweeper < ActionController::Caching::Sweeper
observe Post
def after_save(post)
puts "======================"
puts " AFTER SAVE "
puts "======================"
expire_index
end
private
def expire_index
puts "======================"
puts " EXPIRING INDEX "
puts "======================"
expire_action(:controller => '/posts', :action => 'index')
end
end
config/environments/production.rb
config.action_controller.perform_caching = true
config.cache_store = :dalli_store # using memcachier on heroku
尝试没有 '/' 在控制器选项: expire_action(:控制器=> '帖子',:动作=>“指数') – cthulhu
@cthulhu也不起作用。由于https://github.com/rails/rails/issues/3546,我尝试使用'/'。 –