问题描述
在开发中,以下(简化的)语句总是记录缓存未命中,在生产中它按预期工作:
In development, the following (simplified) statement always logs a cache miss, in production it works as expected:
@categories = Rails.cache.fetch("categories", :expires_in => 5.minutes) do
Rails.logger.info "+++ Cache missed +++"
Category.all
end
如果我在 config/development.rb 中将 config.cache_classes 从 false 更改为 true,它在开发模式下也能正常工作,但是,这会使开发变得相当痛苦.是否有任何类似于 config.cache_classes = false
的配置设置,除非 Rails.cache.fetch 尽可能从缓存中获取?
If I change config.cache_classes from false to true in config/development.rb, it works as well in development mode, however, this makes development rather painful. Is there any configuration setting that is like config.cache_classes = false
except that Rails.cache.fetch is fetching from cache if possible?
推荐答案
尝试在 /config/environments/development.rb 中放置以下内容:
Try placing the following in /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:
Additionally, if your cache store configuration is in /config/environments/production.rb, then you will need to copy the appropriate line into development.rb as well. For example, if your cache store is the Dalli memcache gem:
# copied from production.rb into development.rb for caching in development
config.cache_store = :dalli_store, '127.0.0.1'
希望有所帮助.
这篇关于Rails3 - 使用 Rails.cache.fetch 在开发模式下缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!