0

我根据github 自述文件安装了 nkallen 的 cache-money gem 。我在测试期间遇到了 RecordNotFound 异常。如果我注释掉 config/initializers/cache-money.rb 的内容,测试运行良好。我的 cache-money.rb 文件与 github 说明中的相同。

这是我的 config/memcached.yml 的内容: development: ttl: 604800 namespace: cache-#{RAILS_ENV} sessions: false debug: true servers: localhost:11211

测试:ttl:604800 命名空间:缓存-#{RAILS_ENV} 会话:错误调试:真实服务器:本地主机:11211

生产:ttl:604800 命名空间:缓存-#{RAILS_ENV} 会话:错误调试:错误服务器:本地主机:11211

我找不到有关如何配置或安装缓存货币的任何其他文档。我很感激任何洞察力或帮助调试这个。提前致谢!

4

1 回答 1

2

我将缓存货币配置放入 /config/initializers/cache_money.rb:

if RAILS_ENV != 'development'
  require 'cache_money'

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

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

  class ActiveRecord::Base
    is_cached :repository => $cache
  end
else
  # If we're in development mode, we don't want to
  # deal with cacheing oddities, so let's overrite
  # cache-money's #index method to do nothing...
  class ActiveRecord::Base
    def self.index(*args)
    end
  end
end

无需其他设置。这对我很有用。

于 2009-03-26T01:20:16.473 回答