【问题标题】:Expiration of controller action from Sweeper does not work来自 Sweeper 的控制器操作到期不起作用
【发布时间】:2014-03-17 01:43:43
【问题描述】:

有一个控制器处理大型 XML 提要的呈现

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

下面是对应的扫地机的子类:

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

Spree::FeedSweeper Spree::Product 更新时调用,但似乎expire_action 默默地死掉并且缓存不会失效。

有人可以解释这个问题吗?更好地提出一些解决方案?

谢谢。

【问题讨论】:

    标签: ruby-on-rails ruby spree sweeper


    【解决方案1】:

    您使用的是哪个 Rails 版本?在 Rails 3.2.14 之后,expire_action 似乎是 deprecated

    也许你可以尝试找出密钥然后直接用Rails.cache.delete(key)清除它。

    【讨论】:

    • 我确实使用 Rails 3.2.17。它只是被弃用但仍在工作吗?我在日志中看不到任何错误。
    • 我真的很想避免像手动删除缓存文件这样的黑客行为。如我所见,caches_action 生成一个哈希值并添加到键名之前。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多