【问题标题】:Rails caching only works when expiry is set?Rails缓存仅在设置到期时才有效?
【发布时间】:2014-03-05 09:23:18
【问题描述】:

只是想知道为什么必须设置缓存的到期时间才能在控制台中工作? 显然leaving it out,它应该永远不会过期 - 但我无法让它工作?如果我不设置过期时间,则不会返回密钥。

1.9.3p392 :014 > Rails.cache.write "foo", "bar"
1.9.3p392 :015 > Rails.cache.read "foo"
 => nil 
1.9.3p392 :016 > 
1.9.3p392 :017 > Rails.cache.write "foo", "bar", :expires_in => 3.hours
 => true 
1.9.3p392 :018 > 
1.9.3p392 :019 > Rails.cache.read "foo"
 => "bar" 

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 caching memcached


    【解决方案1】:

    发现从 cache_store 配置中删除“expires_at”可以解决问题。我不需要设置过期时间,因为 memcache 会在它满时清除最旧的等(根据俄罗斯娃娃缓存)。

    config.cache_store = :dalli_store, '127.0.0.1:11211', { :namespace => 'blah', :expires_in => 3.months, :compress => true }
    

    变成

    config.cache_store = :dalli_store, '127.0.0.1:11211', { :namespace => 'blah', :compress => true }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-18
      • 2011-11-04
      • 1970-01-01
      相关资源
      最近更新 更多