Rails sweeper failed expiring cach

84 views Asked by At

I have a sweeper like this, the purpose for this sweeper is very simple, just to expire some caches as you can see in the following code.

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

The weird thing is that this sweeper expires properly with after_update but with after_destroy, no cache is expired. I use 'update' inside my own ArticlesController but 'destroy' is from rails_admin. However, I think the slash in '/articles' makes sure that it matches the correct ::ArticlesController. Do you have any idea? Why cant I expire caches after destroy from rails_admin?

0

There are 0 answers