From 4c23ebd18ce83050469ad203687de263ae95138b Mon Sep 17 00:00:00 2001 From: David Dollar Date: Wed, 16 Jul 2008 23:44:59 -0400 Subject: [PATCH] creates a 'Development' cache storage that changes behavior based on the cache_classes setting When cache_classes is set to fault, much weirdness happens by keeping instances of objects in memory and then wiping/reloading their class definitions out from underneath them. This patch creates a "Development" store that is used by default in the development environment that forces cache misses when cache_classes = false --- activesupport/lib/active_support/cache.rb | 1 + .../lib/active_support/cache/development_store.rb | 15 +++++++++++++++ railties/lib/initializer.rb | 9 +++++---- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 activesupport/lib/active_support/cache/development_store.rb diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 3e3dc18..266938b 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -140,6 +140,7 @@ end require 'active_support/cache/file_store' require 'active_support/cache/memory_store' +require 'active_support/cache/development_store' require 'active_support/cache/drb_store' require 'active_support/cache/mem_cache_store' require 'active_support/cache/compressed_mem_cache_store' diff --git a/activesupport/lib/active_support/cache/development_store.rb b/activesupport/lib/active_support/cache/development_store.rb new file mode 100644 index 0000000..a524b58 --- /dev/null +++ b/activesupport/lib/active_support/cache/development_store.rb @@ -0,0 +1,15 @@ +module ActiveSupport + module Cache + class DevelopmentStore < MemoryStore + + def read(name, options = nil) + Rails.configuration.cache_classes ? super : nil + end + + def exist?(name,options = nil) + Rails.configuration.cache_classes ? super : false + end + + end + end +end \ No newline at end of file diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index b8b071d..24797d0 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -680,6 +680,7 @@ Run `rake gems:install` to install the missing gems. self.view_path = default_view_path self.controller_paths = default_controller_paths self.cache_classes = default_cache_classes + self.cache_store = default_cache_store self.whiny_nils = default_whiny_nils self.plugins = default_plugins self.plugin_paths = default_plugin_paths @@ -872,10 +873,10 @@ Run `rake gems:install` to install the missing gems. end def default_cache_store - if File.exist?("#{root_path}/tmp/cache/") - [ :file_store, "#{root_path}/tmp/cache/" ] - else - :memory_store + case + when RAILS_ENV == 'development' then :development_store + when File.exist?("#{root_path}/tmp/cache/") then [ :file_store, "#{root_path}/tmp/cache/" ] + else :memory_store end end -- 1.5.6.1