views:

624

answers:

1

I installed nkallen's cache-money gem per the github readme. I run into RecordNotFound exceptions during my tests. If I comment out the contents of config/initializers/cache-money.rb, the tests run fine. My cache-money.rb file is identical to that on the github instructions.

Here is the contents of my config/memcached.yml: development: ttl: 604800 namespace: cache-#{RAILS_ENV} sessions: false debug: true servers: localhost:11211

test: ttl: 604800 namespace: cache-#{RAILS_ENV} sessions: false debug: true servers: localhost:11211

production: ttl: 604800 namespace: cache-#{RAILS_ENV} sessions: false debug: false servers: localhost:11211

I can't find any other documentation on how to configuration or install cache-money. I'd appreciate any insight or help to debugging this. Thanks in advance!

+1  A: 

I put my cache-money config into /config/initializers/cache_money.rb:

if RAILS_ENV != 'development'
  require 'cache_money'

  config = YAML.load(IO.read(File.join(RAILS_ROOT, "config", "memcached.yml")))[RAILS_ENV]
  $memcache = MemCache.new(config)
  $memcache.servers = config['servers']

  $local = Cash::Local.new($memcache)
  $lock = Cash::Lock.new($memcache)
  $cache = Cash::Transactional.new($local, $lock)

  class ActiveRecord::Base
    is_cached :repository => $cache
  end
else
  # If we're in development mode, we don't want to
  # deal with cacheing oddities, so let's overrite
  # cache-money's #index method to do nothing...
  class ActiveRecord::Base
    def self.index(*args)
    end
  end
end

No other setup was necessary. This works great for me.

Matt Darby
It looks more like a configuration issue since all queries failed, even simple models.
dr