【发布时间】:2011-08-17 08:57:20
【问题描述】:
我编写了一个 cron 作业来在后台更新一些缓存值(而不是在用户等待时执行)。我有一个场景运行该 cron 作业,然后读取缓存以查看值是否设置正确。
问题是 Rails.cache.read("key") 返回的是 "Cache read: key\n" 而不是值,如果我调试和检查 Rails.cache 我得到一个 ActiveSupport::Cache::BlackHoleStore 返回 - 这不是一个好兆头。
这当然是有道理的,因为我的cucumber.env 中包含以下内容:
config.action_controller.perform_caching = false
require File.join(RAILS_ROOT, 'lib', 'black_hole_store.rb')
config.cache_store = :black_hole_store
我想要的是在运行时覆盖它——我们有大约一千个场景,这是唯一需要激活缓存的场景。我在调试器提示符下尝试了以下操作,但没有任何运气:
(rdb:1) ActionController::Base.perform_caching = true
true
(rdb:1) ActionController::Base.perform_caching
true
(rdb:1) Rails.cache
#<ActiveSupport::Cache::BlackHoleStore:0x101b6dc60 @logger_off=false>
(rdb:1) ActionController::Base.cache_store = :memory_store
:memory_store
(rdb:1) Rails.cache
#<ActiveSupport::Cache::BlackHoleStore:0x101b6dc60 @logger_off=false>
有人知道怎么做吗?
【问题讨论】:
标签: ruby-on-rails caching cucumber cache-control