“rescue in retrieve_store_class”:找不到dalli_store的缓存存储适配器

`rescue in retrieve_store_class': Could not find cache store adapter for dalli_store

提问人:vikasrb 提问时间:7/9/2023 最后编辑:Holger Justvikasrb 更新时间:7/10/2023 访问量:322

问:

使用的版本如下

  • 轨道 5.2.8
  • 红宝石 2.3.1
  • 达利 3.0.4

我收到以下错误:

cache.rb:110:in `rescue in retrieve_store_class': Could not find cache store adapter for dalli_store (cannot load such file -- active_support/cache/dalli_store) (RuntimeError)
def retrieve_store_class(store)
  # require_relative cannot be used here because the class might be
  # provided by another gem, like redis-activesupport for example.
  require "active_support/cache/#{store}"
rescue LoadError => e
  raise "Could not find cache store adapter for #{store} (#{e})"
else
  ActiveSupport::Cache.const_get(store.to_s.camelize)
end

以下代码我已更改,但出现相同的错误。

def retrieve_store_class(store)
  # require_relative cannot be used here because the class might be
  # provided by another gem, like redis-activesupport for example.
  begin #added begin statement after getting error
    require "active_support/cache/#{store}"
  rescue LoadError => e
    raise "Could not find cache store adapter for #{store} (#{e})"
  else
    ActiveSupport::Cache.const_get(store.to_s.camelize)
  end
end
Ruby-on-Rails 红宝石 Ruby-on-Rails-5 Dalli

评论

0赞 smathy 7/10/2023
Rails 5.2.8 active_support/cache 目录中的文件是尝试要求不存在的文件时的预期行为。投票结束。LoadError

答:

1赞 Holger Just 7/10/2023 #1

看来你已经设置了.在 dalli 3.0 之前,dalli gem 本身提供了这种主动支持缓存存储实现。config.cache_store = :dalli_store

从 dalli 2.7.11 开始,缓存存储被弃用了,取而代之的是 Rails 自己的 mem_cache_store 客户端,它在内部使用 dalli。

随着 dalli 3.0.0 的发布,(以及所有其他 rails 特定的代码)从 dalli 中完全删除了。dalli_store

因此,要继续使用 memcache 作为缓存存储,您应该使用 Rails 自己的 .mem_cache_store

参见 https://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-memcachestorehttps://github.com/petergoldstein/dalli/wiki/Using-Dalli-with-Rails 了解如何在 Rails 中使用 dalli 的详细信息。