Google App Engine:如何禁用“静态”文件的缓存或使缓存更加智能 [英] Google App Engine: How to disable cache on 'static' files, or make cache smart

查看:123
本文介绍了Google App Engine:如何禁用“静态”文件的缓存或使缓存更加智能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地使用应用程序引擎,有时会在页面刷新之间缓存JS文件,这让我疯狂,因为我不知道我正在尝试编写的JavaScript代码中是否存在错误,或者如果缓存正在起作用。

如何完全禁用* .js文件的缓存?或者问题是,如何让它变得聪明,就像基于上次修改日期一样。



谢谢!



UPDATE-
所以事实证明,Chrome Dev(至少适用于Mac)具有缓存问题,回到Chrome Beta可以修复所有这些问题。答案仍然有帮助,谢谢

基于文档,您可以指定一个应用程序范围的缓存到期时间:


除非另有说明,否则Web浏览器会保留它们在网站上加载的文件一段有限的时间。您可以通过包含default_expiration元素(一个顶级元素)为应用程序的所有静态文件处理程序定义全局默认缓存期。您还可以为特定的静态文件处理程序配置缓存持续时间。 (脚本处理程序可以通过将适当的HTTP头文件返回给浏览器来设置缓存持续时间。)



default_expiration



如果处理程序没有指定自己的到期时间,则应该在用户的浏览器中缓存静态文件处理程序提供的静态文件的时间长度。值是由空格分隔的数字和单位的字符串,其中单位可以是d天,h为小时,m为分钟,s为秒。例如,4d 5h将缓存过期设置为在浏览器第一次加载文件后4天和5小时。



default_expiration是可选的。如果省略,默认行为是允许浏览器确定自己的缓存持续时间。


...如果您想指定以目录为基础的到期日:

lockquote

过期



此处理程序提供的静态文件应该在用户的浏览器中缓存的时间长度。值是由空格分隔的数字和单位的字符串,其中单位可以是d天,h为小时,m为分钟,s为秒。例如,4d 5h将缓存过期设置为在浏览器第一次加载文件之后4天和5小时。


试试将它们设置为0d0h或1s,看看它是否完全禁用了缓存。


I'm using the app engine locally, and sometimes the JS files are being cached between page refreshes, and it drives me crazy because I don't know if there's a bug in the javascript code I'm trying to write, or if the cache is acting up.

How do I completely disable cache for *.js files? Or maybe the question is, how to have it be smart, like based on last-modified date.

Thanks!

UPDATE- So it turns out Chrome Dev (for mac at least) has caching issues, going back to Chrome Beta fixes all this. The answers have still been helpful though, thanks

解决方案

Based on the docs, you can specify an app-wide cache expiration duration:

Unless told otherwise, web browsers retain files they load from a website for a limited period of time. You can define a global default cache period for all static file handlers for an application by including the default_expiration element, a top-level element. You can also configure a cache duration for specific static file handler. (Script handlers can set cache durations by returning the appropriate HTTP headers to the browser.)

default_expiration

The length of time a static file served by a static file handler ought to be cached in the user's browser, if the handler does not specify its own expiration. The value is a string of numbers and units, separated by spaces, where units can be d for days, h for hours, m for minutes, and s for seconds. For example, "4d 5h" sets cache expiration to 4 days and 5 hours after the file is first loaded by the browser.

default_expiration is optional. If omitted, the default behavior is to allow the browser to determine its own cache duration.

...and if you want to specify the expiration on a directory-by-directory basis:

expiration

The length of time a static file served by this handler ought to be cached in the user's browser. The value is a string of numbers and units, separated by spaces, where units can be d for days, h for hours, m for minutes, and s for seconds. For example, "4d 5h" sets cache expiration to 4 days and 5 hours after the file is first loaded by the browser.

Try setting them to 0d0h or 1s and see if it disables caching entirely.

这篇关于Google App Engine:如何禁用“静态”文件的缓存或使缓存更加智能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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