Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 3 Rails3-使用Rails.cache.fetch在开发模式下进行缓存_Ruby On Rails 3_Caching_Activerecord - Fatal编程技术网

Ruby on rails 3 Rails3-使用Rails.cache.fetch在开发模式下进行缓存

Ruby on rails 3 Rails3-使用Rails.cache.fetch在开发模式下进行缓存,ruby-on-rails-3,caching,activerecord,Ruby On Rails 3,Caching,Activerecord,在开发过程中,以下(简化)语句始终记录缓存未命中,在生产过程中,它按预期工作: @categories = Rails.cache.fetch("categories", :expires_in => 5.minutes) do Rails.logger.info "+++ Cache missed +++" Category.all end 如果我在config/development.rb中将config.cache_类从false更改为true,那么它在开发模式下也可以正常

在开发过程中,以下(简化)语句始终记录缓存未命中,在生产过程中,它按预期工作:

@categories = Rails.cache.fetch("categories", :expires_in => 5.minutes) do
  Rails.logger.info "+++ Cache missed +++"
  Category.all
end

如果我在config/development.rb中将config.cache_类从false更改为true,那么它在开发模式下也可以正常工作,但是,这会使开发变得相当痛苦。如果可能的话,除了Rails.cache.fetch正在从缓存中提取外,是否有任何类似于
config.cache\u classes=false的配置设置?

尝试将以下内容放置在/config/environments/development.rb中:

# Temporarily enable caching in development (COMMENT OUT WHEN DONE!)
config.action_controller.perform_caching = true
此外,如果缓存存储配置位于/config/environments/production.rb,则还需要将相应的行复制到development.rb中。例如,如果您的缓存存储是Dalli memcache gem:

# copied from production.rb into development.rb for caching in development
config.cache_store = :dalli_store, '127.0.0.1' 

希望能有所帮助。

这只是一个额外的提示,添加一个除非ENV[“DEV_CACHE”]将测试配置放入其中,并添加一个包含正常非缓存配置的else。然后,只要您想在终端中启用缓存,就可以编写export DEV_CACHE=“ANYTHING”。最好的一点是,当您不想使用缓存时,您不太喜欢意外启用缓存。此技巧与解决方案一起非常有用。