首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cache-Money:只在生产中使用?

Cache-Money:只在生产中使用?
EN

Stack Overflow用户
提问于 2009-01-17 18:16:18
回答 3查看 2.4K关注 0票数 1

我使用Memcached gem来透明地使用Memcached。使用提供的配置文件,它可以在所有模式(开发、测试、生产)上启用。有没有办法在生产模式下只激活cache-money?

目前还不清楚如何做到这一点,而且在开发模式下处理缓存是一件非常痛苦的事情。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-02-05 20:26:23

感谢Obie Fernandez提供了一个很好的离线提示: Stub out cache-money的#index方法什么都不做。这为模型中的#index语句提供了位置,并停止了上面提到的错误。

下面是我的完整cache_money.rb库:

代码语言:javascript
复制
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
票数 5
EN

Stack Overflow用户

发布于 2009-05-16 20:15:57

通过在测试中关闭cache-money,你不能知道它是否会干扰你的代码。

相反,我这样做了:

代码语言:javascript
复制
require 'cache_money'
require 'memcache'

if RAILS_ENV == 'test'
  $memcache = Cash::Mock.new
else
  config = YAML.load(IO.read(File.join(RAILS_ROOT, "config", "memcached.yml")))[RAILS_ENV]
  $memcache = MemCache.new(config)
  $memcache.servers = config['servers']
end

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

class ActiveRecord::Base
  is_cached :repository => $cache
end
票数 1
EN

Stack Overflow用户

发布于 2009-02-03 21:59:31

在您的初始化器中,如果您在开发模式下运行,请跳过初始化:

代码语言:javascript
复制
unless 'development' == RAILS_ENV
  require 'cache_money'
  ....
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/453755

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档