views:

434

answers:

2

I want to use cache-money but I don't want to start automatically caching everything (I'm working with a large production app, terabytes of data etc). How do I use it for only the models that I specify? Right now I've got:

# initializers/cache_money.rb
require 'cache_money'

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

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

and then in the model I want to cache with cache-money:

# my_model.rb
class MyModel < ActiveRecord::Base
  is_cached :repository => $cache
  # ...
end

But this doesn't work; the call to is_cached gives the following error: NoMethodError: undefined method `create' for Config:Module

Any ideas? Failing that, is there anywhere I can go for help with cache-money? I couldn't find a mailing list or anything.

+1  A: 

I've just experienced the same problem trying to deploy an application. Running on my development machine it was fine, but it failed with this error on the production machine.

Apart from the architecture (OSX vs CentOS) the only difference i could see was that the ruby versions were different (1.8.6 p114 vs 1.8.6 p0). After upgrading the server to the latest 1.8 version (1.8.7 p160) this error went away.

Marc Roberts
argh! I just spent the last day upgrading Ruby (there were many roadblocks) and it didn't fix the problem!An upvote anyway for trying, thanks.
Sam
Maybe we should start a cache_money mailing list ? What rails version are you running (I'm using 2.3.2). The only other thing I had tried was updated rubygems and all my gems. But I think I did that before I upgraded ruby
Marc Roberts
yeah I basically did a complete clean install of ruby, gems, everything and upgraded to 2.3.2 (had been running 2.2.2) and no dice. Got a full plate for the next week or so but hopefully I will get to this eventually and come up with an answer.
Sam
I'm on Ruby 2.3.3 with Ruby 1.9 and I'm still getting the same problem. Any suggestions?
Matt Grande
+3  A: 

I think this is a bug in the cache_money code.

There are forks available on github that fix this bug, eg: http://github.com/quake/cache-money

The fix can be seen with this commit:

http://github.com/quake/cache-money/commit/54c3d12789f31f2904d1fe85c102d7dbe5829590

Lee
That in fact fixed the issue. I can selectively enable cache_money for the models I need
Zepplock