Friday, 27 April 2012

null_store cache for Rails 2

In Rails 3 you can use a fake cache, very useful in development, this uses ActiveSupport::Cache::NullStore, which is not available for Rails 2, but can be easily integrated with some copy and paste with a little customization.
      def initialize
        super # options parameter has been removed 
        extend Strategy::LocalCache
      end
and this is the call
# config/environments/development.rb
require 'vendor/gems/activesupport/cache/null_store.rb' # could also go in environment.rb
# [...]

config.cache_store = :null_store # In Rails 3 it's simply :null 

Update for rails 2.3.18:

Have your file in lib, rather than vendor/gems and have it referenced with full path, something like this:

require "#{Rails.root}/lib/activesupport/cache/null_store.rb"

If every other attempt fail, how about redirecting the cache to dev/null?
config.cache_store = :file_store, "/dev/null"


No comments:

Post a Comment