Rails3 - 使用 Rails.cache.fetch 在开发模式下进行缓存
在开发中,以下(简化的)语句始终记录缓存未命中,在生产中它按预期工作:
@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 如果可能从缓存中获取?
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
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将以下内容放入 /config/environments/development.rb 中:
此外,如果您的缓存存储配置位于 /config/environments/development.rb 中,那么您将需要将相应的行复制到 development.rb 中。例如,如果您的缓存存储是 Dalli memcache gem:
希望有帮助。
Try placing the following in /config/environments/development.rb:
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:
Hope that helps.