缓存的片段不会保留在(Memcachier)缓存中 [英] Cached fragment does not stay in (Memcachier) cache

查看:88
本文介绍了缓存的片段不会保留在(Memcachier)缓存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Heroku,Dalli& amp;上使用Rails 3.1.1. Memcachier.

Using Rails 3.1.1 on Heroku, Dalli & Memcachier.

Production.rb

  config.cache_store = :dalli_store 
  config.action_controller.perform_caching = true

宝石文件

  gem 'memcachier'
  gem 'dalli'

控制器#显示

unless fragment_exist?("gift-show--" + @gift.slug)
 # Perform complicated database query at 4-5 sec
end

查看

<% cache('gift-show--' + @gift.slug, :expires_in => 3456000) do # 40 days %>
  # Create an HTML
<% end %>

加载缓存页面时的日志输出

2012-10-17T03:15:43+00:00 app[web.2]: Started GET "/present/baka-kaka-set" for 23.20.90.66 at 2012-10-17 03:15:43 +0000
2012-10-17T03:15:43+00:00 app[web.2]: Could not find fragment for gift-show--baka-kaka-set # my log comment
2012-10-17T03:15:44+00:00 heroku[router]: GET www.mydomain.com/present/baka-kaka-set dyno=web.2 queue=0 wait=0ms service=195ms status=200 bytes=17167
2012-10-17T03:15:43+00:00 app[web.2]: cache: [GET /present/baka-kaka-set] miss
2012-10-17T03:15:43+00:00 app[web.2]:   Processing by GiftsController#show as */*
2012-10-17T03:15:43+00:00 app[web.2]:   Parameters: {"id"=>"baka-kaka-set"}
2012-10-17T03:15:43+00:00 app[web.2]: Exist fragment? views/gift-show--baka-kaka-set (1.5ms)
2012-10-17T03:15:43+00:00 app[web.2]: Read fragment views/gift-show--baka-kaka-set (1.5ms)
2012-10-17T03:15:43+00:00 app[web.2]: Write fragment views/gift-show--baka-kaka-set (4.0ms)

创建后每个页面几乎都是静态的,因此有效期很长(40天).

Each page is pretty much static once it has been created, thus the long expiry time (40 days).

如果我加载这样的页面,它似乎已写入缓存,则可以通过重新加载页面并确认它绕过控制器(如我期望的那样)并相当快地交付页面来验证这一点.

If I load a page like this it seems to be written to the cache, I can verify that by reloading the page and see that it bypasses the controller (as I expect) and deliver the page quite fast.

我的问题

问题是,如果几分钟后返回页面,该页面已从缓存中删除! fragment_exist?('gift-show--gift-baka-kaka-set')返回false(Rails.cache.exist?('views/gift-show--gift-baka-kaka-set')也是如此)

The problem is that if I return to the page a few minutes later it has already been deleted from the cache! fragment_exist?('gift-show--gift-baka-kaka-set') returns false (so does Rails.cache.exist?('views/gift-show--gift-baka-kaka-set'))

我在Memcachier分析中看到密钥的数量正在减少.即使我运行加载每个页面的脚本(以创建片段缓存),Memcachier中的键数也不会以相同的速率增加.

I can see in the Memcachier analytics that the number of keys are decreasing. Even when I run a script that load each page (to create fragment caches) the number of keys in Memcachier does not increase in the same rate.

在Memcachier中,我的内存使用量约为34%,所以我还没有达到极限.

I am at about 34% of memory usage in Memcachier, so I am not close to the limit.

我的问题

我做错了什么吗?我该怎么办?

Am I doing something complete wrong? What should I rather do?

是我正在写两个不同的缓存还是什么?

Could it be that I am writing to two different caches or something?

日志文件的最后一行使我有些困惑.似乎即使读取了一个片段之后,仍在写一个新的片段?那很奇怪吗?

The last line in the log file confuses me a bit. It seems like that even after a fragment is read, a new one is still being written? Is that weird?

更新1 :我意识到我已经注释掉了这一行:

UPDATE 1: I realized I had commented out the line:

  # Set expire header of 30 days for static files
  config.static_cache_control = "public, max-age=2592000"

之前.那会导致问题吗?缓存的动作是否被视为静态资产"?

before. Could that have caused the problem? Are cached actions considered 'static assets'?

推荐答案

原来是Memcachier中的错误. Memcachier支持得出了这一结论,并且与Memcache配合使用时效果很好. Memcachier将尝试修复该错误.

Turned out to be a bug in Memcachier. Memcachier support came to this conclusion and it works fine with Memcache. Memcachier will try to fix the bug.

这篇关于缓存的片段不会保留在(Memcachier)缓存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆