0

私はこのようなスイーパーを持っています。このスイーパーの目的は非常に単純で、次のコードでわかるようにいくつかのキャッシュを期限切れにするだけです。

module CustomSweeper
  class ArticleSweeper < ActionController::Caching::Sweeper
    observe Article

    def after_update(record)
      expire_cache record
      Rails.logger.debug 'After_update sweeper is activated'
    end

    def after_destroy(record)
      expire_cache record
      Rails.logger.debug record.inspect
      Rails.logger.debug 'After_destroy sweeper is activated'
    end

    private
    def expire_cache(record)
      Rails.logger.debug 'Going to expire index and show'
      expire_action :controller => '/articles', :action => 'index'
      expire_action :controller => '/articles', :action => 'show', :id => record.id
      Rails.logger.debug 'End expiring index and show'
    end
  end
end

奇妙なことに、このスイーパーは after_update で適切に期限切れになりますが、after_destroy ではキャッシュの期限が切れません。自分の ArticlesController 内で「update」を使用していますが、「destroy」は rails_admin からのものです。ただし、「/articles」のスラッシュにより、正しい ::ArticlesController と一致することが保証されると思います。何か考えはありますか?rails_admin から破棄した後にキャッシュを期限切れにできないのはなぜですか?

4

0 に答える 0