防止缓存动态(php)内容 [英] Prevent caching of dynamic (php) content

查看:77
本文介绍了防止缓存动态(php)内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试设置适当的缓存,但是我无法获取动态部分。

I've attempted to set up appropriate caching, however I'm having trouble getting the dynamic portions through.

您可以在此处看到有问题的站点:< a href = http://nathanhornby.com rel = nofollow> nathanhornby.com
和此处的仓库: https://github.com/nathanhornby/nathanhornby.com

You can see the site in question here: nathanhornby.com And the repo here: https://github.com/nathanhornby/nathanhornby.com

您会看到有3个供稿在底部。问题在于,如果现在加载页面,它似乎已被缓存,因此,每次加载时,您将看到完全相同的内容,需要用户强制刷新才能看到新内容,这自然是不切实际的

As you'll see there are 3 feeds at the bottom. The issue is that if you load up the page now, it seems to be cached, and therefore every time you load it you'll see the exact same content, requiring a user force-refresh to see the new content, which is naturally impractical.

**注意:**我在说的是页面缓存,而不是提要缓存。提要确实缓存,但这是有意的,但是如果提要更改,则仅在用户刷新后才会反映出来。 时间之前是相同的。如果是第一次加载 9分钟前,则下次加载时会说相同的话。但是刷新页面会更新该时间。

** Note: ** I'm talking about the page caching, not the feed caching. The feeds do cache, this is intentional, but if the feed changes this is only reflected if the user refreshed. The 'time ago' is the same. If it said '9 minutes ago' the first time you load it, it'll say the same thing the next time you load it. But refreshing the page will update that time.

您可以在此处查看我的.htaccess设置: https://github.com/nathanhornby/nathanhornby.com/blob/master/.htaccess

You can see my .htaccess setup here: https://github.com/nathanhornby/nathanhornby.com/blob/master/.htaccess

我希望本节能够满足我的需要,但似乎不会:

I would hope that this section does what I need, but it doesn't seem to:

#禁用PHP缓存
< FilesMatch \。(pl | php | cgi | spl | scgi | fcgi)$>
标头未设置Cache-Control
< / FilesMatch>

什么是最好的方式来确保在加载时提供新鲜的内容而无需刷新?

What's the best way to ensure that fresh content is served on load, without the need for a refresh?

推荐答案

您说的是您想要没有页面刷新的新鲜内容。为此,您将需要其他诸如JQuery和AJAX之类的功能,禁用缓存不会使页面不刷新就可以自行更新。

Your saying that you want fresh content without a page refresh. For that you will need something else such as JQuery and AJAX, disabling caching won't make pages update themselfs without refresh.

这是您想要的吗?

 <FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
    FileETag None
    <ifModule mod_headers.c>
        Header unset ETag
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </ifModule>
 </FilesMatch>

来源: http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html

这篇关于防止缓存动态(php)内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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