Use cache money only for a single model?

Deadly 提交于 2019-12-07 11:41:41

问题


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:


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




回答2:


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.



来源:https://stackoverflow.com/questions/837007/use-cache-money-only-for-a-single-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!