代码之家  ›  专栏  ›  技术社区  ›  Jason

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

  •  1
  • Jason  · 技术社区  · 15 年前

    在我的Posts controller中,我有:

    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
    

    2 回复  |  直到 15 年前
        1
  •  0
  •   fstephany    15 年前

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

        2
  •  0
  •   VP.    14 年前

    可能你没有在你的装载路径中添加清扫器

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

    您的清扫器所在的目录。