Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从Rails控制台使用Rails.cache-它如何知道如何加载密钥_Ruby On Rails_Caching - Fatal编程技术网

Ruby on rails 从Rails控制台使用Rails.cache-它如何知道如何加载密钥

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 当我进入

我有一个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
当我进入rails控制台并键入

Rails.cache.fetch('cache\u key')
我得到了结果

然后我像这样删除它:
Rails.cache.delete('cache\u key')
,它返回
=>true

然后我再次提取Rails.cache.fetch('cache\u key'),然后我再次得到正确的结果

问题是:如果我没有向rails.cache.fetch方法提供一个块(该块应该告诉rails缓存如何加载该键的数据,对吗?),如何获得正确的数据

不知为什么,由于我不知道的原因,数据是自动获取的