【问题标题】:Weird cacheing issues with heroku / memcache and dalliheroku / memcached 和 dalli 的奇怪缓存问题
【发布时间】:2011-10-30 16:18:34
【问题描述】:

考虑以下问题。从我的 Heroku 控制台:

>> Rails.cache.stats
=> {"server_id"=>{"evictions"=>"0", "curr_items"=>"2064", "total_items"=>"18793", "bytes"=>"7674501", ...
>> Rails.cache.clear
=> [true]
>> Rails.cache.stats
=> {"server_id"=>{"evictions"=>"0", "curr_items"=>"2064", "total_items"=>"18793", "bytes"=>"7674501",

超级奇怪——我怎样才能清除我的缓存!!


类似的问题? :https://stackoverflow.com/q/7122513/192791

【问题讨论】:

  • 您是否尝试过Rails.cache.read('key'),您知道该特定键的缓存中存储了一个值。正如@b-r-o-s 提到的那样,统计数据并不总是立即更新,但如果您尝试从缓存中读取,那么它应该立即返回 nil。
  • 我遇到了类似的情况,我运行 Rails.cache.clear 如果我想看到缓存重新加载,我必须重新启动我的实例。很奇怪。

标签: ruby-on-rails heroku memcached


【解决方案1】:

如果您通过控制台直接连接到 Dalli/memcahced 客户端并 flush_all 缓存将被清除。

dc = Dalli::Client.new('localhost:11211')
dc.flush_all

注意:统计数据需要一段时间才能更新,但缓存肯定会清除。

【讨论】:

【解决方案2】:

http://devcenter.heroku.com/articles/building-a-rails-3-application-with-the-memcache-addonExpiring Cache 部分建议使用过滤器

after_save    :expire_contact_all_cache
after_destroy :expire_contact_all_cache

def expire_contact_all_cache
  Rails.cache.delete('Contact.all')
end

【讨论】:

  • 这对视图中的片段不起作用——是吗?
  • 谢谢你——我不是在寻找一个过期的缓存策略——我想知道为什么 Rails.cache.clear 没有清除缓存。 (当我发布新版本时——我想彻底清除缓存)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-04
  • 1970-01-01
  • 2013-01-11
  • 2016-08-17
  • 2019-01-07
相关资源
最近更新 更多