Rails 使用 Solid Cache 进行低级缓存:收到“警告:已初始化常量”

问题描述 投票:0回答:1

我正在尝试使用 Rails“低级缓存”和 Solid Cache 缓存一些查询数据 - 非常简单的东西。

这是我的缓存方法:

class Location < ApplicationRecord
  def self.location_name_cache
    Rails.cache.fetch(:location_names, expires_in: 15.minutes) do
      (Location.pluck(:name) + Observation.pluck(:where)).uniq
    end
  end

  # Check if a given place name already exists, defined as a Location name string.
  def self.location_name_exists(name)
    location_name_cache.member?(name)
  end

但是当我对我的类方法进行单元测试(使用 Minitest)时,尽管测试通过了,但我收到了这些警告:

warning: already initialized constant SolidCache::Record::NULL_INSTRUMENTER
warning: previous definition of NULL_INSTRUMENTER was here

我做错了什么?

我已经尝试过

bundle clean --force
bundle install
以防它是陈旧的宝石,但这是唯一出现的问题search似乎与我的情况相符。

这是我的缓存配置:

# config/application.rb
  config.cache_store = :solid_cache_store
  config.solid_cache.connects_to = { database: { writing: :cache } }

# config/environments/test.rb - idk if these are relevant
  config.cache_classes = true
  config.action_view.cache_template_loading = true

# config/environments/development.rb - probably not relevant
  # Enable/disable caching. By default caching is disabled.
  # Run rails dev:cache to toggle caching.
  if Rails.root.join("tmp/caching-dev.txt").exist?
    config.action_controller.perform_caching = true
    # debugging: log fragment reads/writes
    # (it will show [cache hit] even if set to false)
    config.action_controller.enable_fragment_cache_logging = true

    config.cache_store = :memory_store # :mem_cache_store via application.rb
    config.public_file_server.headers = {
      "Cache-Control" => "public, max-age=#{2.days.to_i}"
    }
  else
    config.action_controller.perform_caching = false
  end
或者这是数据库无论如何都会缓存结果的情况,并且缓存是不可取的?
ruby-on-rails caching
1个回答
0
投票

这已经被作者调试过。事实证明,gem 的错误处理正在吞噬“缓存数据库配置错误”。 修复正在进行中

© www.soinside.com 2019 - 2024. All rights reserved.