仅将缓存资金用于单个模型

仅将缓存资金用于单个模型

本文介绍了仅将缓存资金用于单个模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用缓存资金,但是我不想开始自动缓存所有内容(我正在使用大型生产应用程序,数TB的数据等).如何仅将其用于指定的模型?现在我有:

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)

,然后在该模型中,我想用cache-money进行缓存:

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

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

但这是行不通的;调用is_cached会出现以下错误:NoMethodError:Config:Module的未定义方法"create"

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.

推荐答案

我认为这是cache_money代码中的错误.

I think this is a bug in the cache_money code.

在github上有可用的fork来修复此错误,例如: http://github.com/quake/cache-money

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/54c3d12789f31f2904d1fe85c102590

这篇关于仅将缓存资金用于单个模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 18:47