本文介绍了Rails3 - 缓存与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

如果我改变config.cache_classes从虚假到真实的配置/ development.rb,它的工作原理以及在开发模式,然而,这使得开发比较痛苦。是否有任何配置设置,就像 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

# Temporarily enable caching in development (COMMENT OUT WHEN DONE!)
config.action_controller.perform_caching = true

此外,如果你的缓存存储配置是 /config/environments/production.rb ,然后你将需要适当的行复制到 development.rb 以及。例如,如果你的缓存存储的是达利的memcache宝石:

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'

希望有所帮助。

Hope that helps.

这篇关于Rails3 - 缓存与Rails.cache.fetch发展模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 01:03