我想使用 cache-money 但我不想开始自动缓存所有内容(我正在使用大型生产应用程序、TB 级数据等)。如何仅将它用于我指定的模型?现在我有:
# 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)
然后在模型中我想使用 cache-money 进行缓存:
# my_model.rb
class MyModel < ActiveRecord::Base
is_cached :repository => $cache
# ...
end
但这行不通;对 is_cached 的调用给出了以下错误:NoMethodError: undefined method `create' for Config:Module
有什么想法吗?如果做不到这一点,有什么地方可以寻求缓存资金方面的帮助吗?我找不到邮寄列表或任何东西。
最佳答案
我认为这是 cache_money 代码中的错误。
github 上有修复此错误的可用分支,例如: http://github.com/quake/cache-money
可以通过此提交看到修复:
http://github.com/quake/cache-money/commit/54c3d12789f31f2904d1fe85c102d7dbe5829590
关于ruby-on-rails - 仅对单个模型使用缓存资金?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/837007/