Rails Active Model Serializers - 如何手动使缓存失效?

时间:2015-03-30 19:11:09

标签: ruby-on-rails caching active-model-serializers

我正在使用Active Model Serializers在我的Rails应用程序中缓存模型。我希望它缓存,但我不希望缓存在关联对象(User的实例)更新时过期。我想要的是能够在我想要的时候(与用户更新无关)使它过期,并且只有在它被迫这样做时才会过期。

序列化代码如下所示:

class MatchesHashSerializer < ActiveModel::Serializer
  cached
  delegate :cache_key, to: :object

  attribute :matches_hash

  def matches_hash
    ...
  end
end

我仍然希望缓存与用户对象相关联,但我只是不希望它在用户更新时过期 - 我只希望它通过触发/强制它与其他一些过期而到期机制。我该怎么做?

谢谢!

0 个答案:

没有答案