Ruby on rails 从Rails控制台使用Rails.cache-它如何知道如何加载密钥
我有一个rails缓存,配置如下Ruby on rails 从Rails控制台使用Rails.cache-它如何知道如何加载密钥,ruby-on-rails,caching,Ruby On Rails,Caching,我有一个rails缓存,配置如下 config.cache\u store=:dalli\u store,… 在模型中的一种方法中,我有: def get_some_data @industry_groups_field_options ||= Rails.cache.fetch('cache_key', expires_in: 1.hour) do #the data fetching code goes here - it works fine end end 当我进入
config.cache\u store=:dalli\u store,…
在模型中的一种方法中,我有:
def get_some_data
@industry_groups_field_options ||= Rails.cache.fetch('cache_key', expires_in: 1.hour) do
#the data fetching code goes here - it works fine
end
end
当我进入rails控制台并键入
Rails.cache.fetch('cache\u key')
我得到了结果
然后我像这样删除它:Rails.cache.delete('cache\u key')
,它返回=>true
然后我再次提取Rails.cache.fetch('cache\u key'),然后我再次得到正确的结果
问题是:如果我没有向rails.cache.fetch方法提供一个块(该块应该告诉rails缓存如何加载该键的数据,对吗?),如何获得正确的数据
不知为什么,由于我不知道的原因,数据是自动获取的