使用nginx/passenger/memcached/rails的最大年龄2.3.5 [英] max age with nginx/passenger/memcached/rails2.3.5

查看:80
本文介绍了使用nginx/passenger/memcached/rails的最大年龄2.3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在我的生产环境(我实现了memcached的生产环境)中,无论何时我在查看索引页面(例如,帖子)时,都看到firebug中的cache-control-max-age标头.

I notice that in my production enviornment (where I have memcached implemented) in see a cache-control - max-age header in firebug, anytime I am looking at an index page (posts for example).

Cache-Control   max-age=315360000

在我的开发环境中,标头如下所示.

In my dev environment that header looks like following.

Cache-Contro private, max-age=0, must-revalidate

据我所知,我对nginx.conf文件没有做任何特别的事情来为常规内容指定最长使用期限,但我确实为css,jpg等设置了expires-max.这是我的nginx.conf文件.

As far as I know I have not done anything special with my nginx.conf file to specify max age for regular content, I do have expires-max set for css, jpg etc. here is my nginx.conf file..

http://pastie.org/1167080

那么为什么要设置此缓存控件?我该如何控制此缓存控件,因为这样做的副作用有点不好.这就是发生的情况.

So why is this cache-control is being set? How can I control this cache-control, because the side effect of this is kinda bad. This is what happens.

1-用户请求all_posts列表并获得10页的列表(分页)

1 - User request all_posts listing and get a list of 10 pages (paginated)

2-用户视图页面1、2 3和相应的缓存已创建.

2 - User view page 1, 2 3 and the respective caches are created.

3-用户返回到第1页,firefox甚至没有向服务器发出请求.通常,我希望它会要求执行并命中在步骤2中创建的缓存.

3 - User goes back to page 1 and firefox does not even make a request to the server. Normally I would expect it would reqeust and hit the cache created in step #2.

另一个问题是,如果创建了一个新帖子,并且现在刷新了缓存,并且该缓存应该位于页面1的顶部,那么用户将无法看到它.服务器.

The other issue is that if a new post has been created and now the cache is refreshed and it should be at the top of page 1, the user does not get to see it..because the browser isn't hitting the server.

请帮助!

谢谢

更新:

我尝试在索引操作中设置expires_now.最大年龄没有差别,仍然是相同的大值.

I tried setting expires_now in my index action. NO difference the max-age is still the same large value.

这是我的max-age正则表达式的问题吗?我基本上希望它只匹配资产文件(图像,js,css等)

Could this be a problem with my max-age regex? I basically want it to match only asset files(images, js, css etc)

推荐答案

我认为您说对了,这是您的max-age regex问题.

I think you're right that this is a problem with your max-age regex.

您正在与此模式匹配:^.+.(jpg|jpeg|gif|png|css|js|swf)?([0-9]+)?$

You're matching against this pattern: ^.+.(jpg|jpeg|gif|png|css|js|swf)?([0-9]+)?$

因为两个括号部分之后都有问号(此部分是可选的"),所以正则表达式的唯一必需部分是请求URI至少包含两个字符(.+.).换句话说,它几乎可以匹配您网站上的每个请求.

Because you have question marks ("this part is optional") after both parenthesized sections, the only mandatory part of the regex is that the request URI have at least two characters (.+.). In other words, it's matching pretty near every request to your site.

这是我们使用的模式:\.(js|css|jpg|jpeg|gif|png|swf)$

This is the pattern we use: \.(js|css|jpg|jpeg|gif|png|swf)$

这将仅匹配对路径的请求,该请求以点号结尾,然后是这七个模式之一.

That will match only requests for paths ending with a dot and then one of those seven patterns.

这篇关于使用nginx/passenger/memcached/rails的最大年龄2.3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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