ruby-on-rails - 仅对单个模型使用缓存资金?

标签 ruby-on-rails ruby memcached cache-money

我想使用 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/

相关文章:

ruby - ruby 会自动调用初始化方法吗?

magento - session 的 magento + memcache 中的 session.save_path 不正确

ruby-on-rails - Memcache 在 Rails 3 中的基本使用

php - 收到警告 "PHP Startup: Unable to load dynamic library"

ruby-on-rails - cucumber 在没有 spork 的情况下工作正常,但是 spork 给了我 "uninitialized constant Cucumber::Rails"

ruby - 为什么单个空数组的并行赋值会分配多个nil?

ruby-on-rails - ruby rails : Limit user to endorse(comment) 3 other users a month

ruby-on-rails - 哈希中时间戳的 Rspec 问题

ruby-on-rails - 在 Windows 虚拟机上运行的 Rails

ruby-on-rails - rails : Restrict API requests to JSON format