0
我试图初始化我缓存在application.rb中,使其得到应用在application.rb中
我application.rb中看起来初始化后填充使用Rails.cache为:
config.cache_store = :memory_store
config.after_initialize do
Rails.cache.write('key','value)
puts Rails.cache.read('key')
end
Rails.cache.read('key')
在这里给出一个空值
但是如果我把相同的代码放在rails的其他ruby类中,它会给出预期的输出。
例my_cache.rb
Rails.cache.write('key','value')
puts Rails.cache.read('key') # gives output value
为了提供更多的背景,我也得到这个怪异的行为我Rails.cache在两个application.rb中和my_cache.rb一个ActiveSupport::Cache::NullStore
,在这里我想应该是一个ActiveSupport::Cache::MemoryStore
我使用的铁轨5.1.0