ActiveModel :: Serializer Caching - ThreadSafe :: Cache的未定义方法`fetch_or_store'

时间:2015-05-27 18:25:29

标签: ruby caching thread-safety active-model-serializers rails-api

我刚刚将我的AMS gem升级到0.10.0.rc1,希望获得更好的缓存功能。我试图缓存一些AppLabel,序列化器看起来像这样:

class AppLabelSerializer < ActiveModel::Serializer
  cache key: 'app_label', expires_in: 3.hours
  attributes :id, :key, :label, :label_plural

  def key
    object.app_label_dictionary.key
  end

end

然后我用PostMan打了一个AppLabel端点,我收到了这个错误:

NoMethodError (undefined method `fetch_or_store' for #<ThreadSafe::Cache:0x007fcf70821378>):
  app/controllers/v1/app_labels_controller.rb:22:in `auth_index'

我在第22行检查了app_labels_controller.rb,这是方法:

def auth_index
  render json: AppLabel.non_event
end

这是在调用AppLabel范围:

scope :non_event, -> {joins(:app_label_dictionary).where(app_label_dictionary: {event_label: false} )}

我对AMS缓存或Rails的Threadsafe元素不太熟悉,不知道这里发生了什么。

有什么想法吗?

0 个答案:

没有答案