Is there a way to make Rails.cache.fetch always execute the code block in the test environment? (disable caching) For example in my test console on Rails 3 ruby-1.9.2-rc2 > Rails.cache.fetch(''foo'') {''bar''} => "bar" ruby-1.9.2-rc2 > Rails.cache.fetch(''foo'') {''bar44''} => "bar" Caching is on. Using filestore ruby-1.9.2-rc2 > Rails.cache => #<ActiveSupport::Cache::FileStore Is there a ActiveSupport::Cache::Store implementation that doesn''t cache? I''m assuming I''m just missing something trivial since this is easily disabled for page/action/fragment caching with config.action_controller.perform_caching = false I have... ruby-1.9.2-rc2 > Rails.application.config.action_controller.perform_caching => false What am I missing? Thanks Tony -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2 solutions... If you want caching on in test mode (good way to test it is doing what you expect) you can simply clear the cache between tests. def setup Rails.cache.clear end Or you can write a cache that doesn''t store anything. put this in lib/active_support/cache/no_store.rb module ActiveSupport module Cache class NoStore < Store def read_entry(name, options) return nil end def write_entry(name, value, options) end def delete_entry(name, options) end end end end then add config.cache_store = :no_store to your test.rb file. On Sep 2, 9:20 am, Tony Primerano <tony.primer...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is there a way to make Rails.cache.fetch always execute the code block > in the test environment? (disable caching) > > For example in my test console on Rails 3 > > ruby-1.9.2-rc2 > Rails.cache.fetch(''foo'') {''bar''} > => "bar" > ruby-1.9.2-rc2 > Rails.cache.fetch(''foo'') {''bar44''} > => "bar" > > Caching is on. Using filestore > > ruby-1.9.2-rc2 > Rails.cache > => #<ActiveSupport::Cache::FileStore > > Is there a ActiveSupport::Cache::Store implementation that doesn''t > cache? I''m assuming I''m just missing something trivial since this is > easily disabled for page/action/fragment caching with > > config.action_controller.perform_caching = false > > I have... > ruby-1.9.2-rc2 > > Rails.application.config.action_controller.perform_caching > => false > > What am I missing? Thanks > Tony-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You can also use the following in your environment configuration: config.cache_store = :null_store Cheers, JP On Thursday, 2 September 2010 07:20:30 UTC-6, Tony Primerano wrote:> > Is there a way to make Rails.cache.fetch always execute the code block > in the test environment? (disable caching) > > For example in my test console on Rails 3 > > ruby-1.9.2-rc2 > Rails.cache.fetch(''foo'') {''bar''} > => "bar" > ruby-1.9.2-rc2 > Rails.cache.fetch(''foo'') {''bar44''} > => "bar" > > Caching is on. Using filestore > > ruby-1.9.2-rc2 > Rails.cache > => #<ActiveSupport::Cache::FileStore > > Is there a ActiveSupport::Cache::Store implementation that doesn''t > cache? I''m assuming I''m just missing something trivial since this is > easily disabled for page/action/fragment caching with > > config.action_controller.perform_caching = false > > I have... > ruby-1.9.2-rc2 > > Rails.application.config.action_controller.perform_caching > => false > > What am I missing? Thanks > Tony > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9af84faa-2283-4550-ae2d-690e53a0a8c7%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.