Expiration of controller action from Sweeper does not work

200 Views Asked by At

Having a controller handling rendering of large XML feeds

module Spree
  class FeedsController < Spree::StoreController
    ...

    caches_action :products_out
    cache_sweeper FeedSweeper

    # XML feed in format of `xxxxxxx.com'
    def products_out
      @products = Product.all
      respond_to do |format|
        format.xml
      end
    end
end

Bellow is the corresponding sweeper's sublass:

module Spree
  class FeedSweeper< ActionController::Caching::Sweeper
    observe Product

    def after_update(product)
      # cache_configured? is nil, @controller is nil here, why ?
      expire_action(:controller => :feeds,
                    :action     => :products_out,
                    :format     => :xml)
    end
end

Above Spree::FeedSweeper is called when Spree::Product gets updated, however it seems expire_action silently dies and cache won't get invalidated.

Can somebody explain the issue ? Even better suggest some solution ?

Thanks.

1

There are 1 best solutions below

2
Benjamin Tan Wei Hao On

Which Rails version are you using? expire_action seems to be deprecated after Rails 3.2.14.

Maybe you can try to find out the key then directly clear it with Rails.cache.delete(key).