观察者没有在Rails 2.3.2中清除缓存 - 请帮助

时间:2010-06-01 00:25:33

标签: ruby-on-rails caching memcached

我们正在使用Rails 2.3.2,Ruby 1.8&内存缓存。

在我的帖子控制器中,我有:

cache_sweeper Company::Caching::Sweepers::PostSweeper, :only => [:save_post]

我创建了以下模块:

module Company
  module Caching
    module Sweepers

      class PostSweeper < ActionController::Caching::Sweeper
        observe Post

        def after_save(post)
          Rails.cache.delete("post_" + post.permalink)
        end
      end

    end
  end
end

但是当调用save_post方法时,永远不会删除缓存。只是希望有人能在这里看到我做错了什么。感谢。

2 个答案:

答案 0 :(得分:0)

如果控制器中的操作被调用save_post,则应该调用您的清扫方法after_save_post(post)

答案 1 :(得分:0)

可能您没有在加载路径中添加清扫程序

 config.load_paths += %W( #{RAILS_ROOT}/app/models/cache )

目录是您的清扫工所在的位置。