From 1538ea1443b45faf0a70c3cae824e8b635f08821 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Mon, 11 Aug 2008 15:23:34 -0700 Subject: [PATCH] disable caching by default in development with NoStore which always returns nil on read --- activesupport/lib/active_support/cache.rb | 1 + activesupport/lib/active_support/cache/no_store.rb | 10 ++++++++++ activesupport/test/caching_test.rb | 16 ++++++++++++++++ railties/lib/initializer.rb | 5 +++-- 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 activesupport/lib/active_support/cache/no_store.rb diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 95eae3a..0c395e4 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -119,3 +119,4 @@ require 'active_support/cache/memory_store' require 'active_support/cache/drb_store' require 'active_support/cache/mem_cache_store' require 'active_support/cache/compressed_mem_cache_store' +require 'active_support/cache/no_store' diff --git a/activesupport/lib/active_support/cache/no_store.rb b/activesupport/lib/active_support/cache/no_store.rb new file mode 100644 index 0000000..46a44b9 --- /dev/null +++ b/activesupport/lib/active_support/cache/no_store.rb @@ -0,0 +1,10 @@ +module ActiveSupport + module Cache + class NoStore < Store + def read(name, options = nil) + super + nil + end + end + end +end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index f3220d2..1011302 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -70,3 +70,19 @@ uses_mocha 'high-level cache store tests' do end end end + + +class NoStoreTest < Test::Unit::TestCase + def setup + @cache = ActiveSupport::Cache.lookup_store(:no_store) + end + + def test_read_should_always_return_nil + @cache.write('foo', 'bar') + assert_nil @cache.read('foo') + end + + def test_fetch_should_return_object_in_block + assert_equal 'bar', @cache.fetch('foo') { 'bar' } + end +end diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 6576cd3..50bc9c5 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -745,6 +745,7 @@ Run `rake gems:install` to install the missing gems. self.database_configuration_file = default_database_configuration_file self.routes_configuration_file = default_routes_configuration_file self.gems = default_gems + self.cache_store = default_cache_store for framework in default_frameworks self.send("#{framework}=", Rails::OrderedOptions.new) @@ -949,8 +950,8 @@ 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/" ] + if environment == 'development' + :no_store else :memory_store end -- 1.5.6.4