代码之家  ›  专栏  ›  技术社区  ›  Matt Darby

缓存资金:仅用于生产?

  •  1
  • Matt Darby  · 技术社区  · 16 年前

    我使用 cache-money

    3 回复  |  直到 16 年前
        1
  •  5
  •   Matt Darby    16 年前

    幸亏 Obie Fernandez 对于一个伟大的离线提示:stubout cache money的#index方法什么也不做。这为模型中的#index语句提供了一个位置,并停止了上述错误。

    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
    
        2
  •  1
  •   Bob Cotton Bob Cotton    15 年前

    通过在测试中关闭缓存金钱,您无法知道它是否会干扰您的代码。

    我改为:

    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
    
        3
  •  0
  •   wesgarrison    16 年前

    unless 'development' == RAILS_ENV
      require 'cache_money'
      ....