问题描述
我的Django通过mod_wsgi的Apache中运行。我相信Django的是缓存我的网页服务器端,这是造成某些功能无法正常工作。
I have Django running in Apache via mod_wsgi. I believe Django is caching my pages server-side, which is causing some of the functionality to not work correctly.
我有一个倒计时器,通过获取当前的服务器时间,确定剩余的倒计时,并输出这个数字到HTML模板工程。然后一个Javascript倒计时接管并运行用户在倒计时。
I have a countdown timer that works by getting the current server time, determining the remaining countdown time, and outputting that number to the HTML template. A javascript countdown timer then takes over and runs the countdown for the user.
当用户刷新页面,或者导航与倒数计时器一个不同的页面,就会出现问题。计时器出现零星各地跳转到不同的时间,通常在每次刷新回到同一时间一遍又一遍。
The problem arises when the user refreshes the page, or navigates to a different page with the countdown timer. The timer appears to jump around to different times sporadically, usually going back to the same time over and over again on each refresh.
使用的是HttpFox,页面不是从我的浏览器缓存加载,所以看起来不是Django的或Apache是缓存的页面。有什么办法禁用此功能?我不会有足够的流量,不用担心缓存脚本输出。还是我完全错了,为什么会这样?
Using HTTPFox, the page is not being loaded from my browser cache, so it looks like either Django or Apache is caching the page. Is there any way to disable this functionality? I'm not going to have enough traffic to worry about caching the script output. Or am I completely wrong about why this is happening?
从下面的文章,它看起来像高速缓存在Django停用的,这意味着它必须在其他地方发生的事情,也许在阿帕奇?
From the posts below, it looks like caching is disabled in Django, which means it must be happening elsewhere, perhaps in Apache?
我有什么正在发生的事情进行更彻底的说明:对于向服务器发出的第7(左右)的请求,该页面由脚本提供,而且回来了,虽然每次的7页似乎是缓存为后来出现了。 8号请求,服务器提供向上的第一页。在第9个请求时,它在一个周期提供了第二页,等等。这一直持续到我重启apache,当进程再次开始。
I have a more thorough description of what is happening: For the first 7 (or so) requests made to the server, the pages are rendered by the script and returned, although each of those 7 pages seems to be cached as it shows up later. On the 8th request, the server serves up the first page. On the 9th request, it serves up the second page, and so on in a cycle. This lasts until I restart apache, when the process starts over again.
我已经配置的mod_wsgi到的时间,这使得定时器重置为在所有情况下相同的值仅运行一个过程。但有趣的是,有这么对每个请求显示一个随机图像,使用顺序(?)我的页面上的另一个组成部分,而且也与不同的图像,每次,这表明缓存是发生在Django而不是在Apache的刷新。
I have configured mod_wsgi to run only one process at a time, which causes the timer to reset to the same value in every case. Interestingly though, there's another component on my page that displays a random image on each request, using order('?'), and that does refresh with different images each time, which would indicate the caching is happening in Django and not in Apache.
在previous编辑的光,我回去和审查相关的views.py文件,发现倒数开始变量正在模块中的全局设置,的观点之外的功能。移动解决问题的观点函数中该设置。因此,它竟然不是一个缓存的问题毕竟。谢谢大家对你对这个帮助。
In light of the previous edit, I went back and reviewed the relevant views.py file, finding that the countdown start variable was being set globally in the module, outside of the view functions. Moving that setting inside the view functions resolved the problem. So it turned out not to be a caching issue after all. Thanks everyone for your help on this.
推荐答案
从我与阿帕奇mod_wsgi的经验,这是极不可能的,他们所造成的缓存。几件事情尝试:
From my experience with mod_wsgi in Apache, it is highly unlikely that they are causing caching. A couple of things to try:
- 这是可能的,你有你的电脑,这是适当或不适当缓存Web服务器之间的一些页面。有时,互联网服务提供商运行代理服务器,以减少他们的网络之外的带宽。能否请您为这是获得高速缓存(萤火虫能为你们给这些)页面的HTTP标头。头,我会特别有兴趣在包括缓存控制,过期,最后修改,和ETag。
- 您可以从您的settings.py文件发表您的MIDDLEWARE_CLASSES。这可能是你有对你进行高速缓存的中间件。
- 您可以grep你的code以下项目的加载缓存,django.core.cache和cache_page。 A *的grep -R搜索**会工作。
- 请问settings.py(或任何其进口,如从localsettings导入*)包括CACHE_BACKEND?
- 当你重新启动Apache会发生什么? (例如须藤服务apache和重启)。如果启动将清除问题,那么它可能是阿帕奇做缓存(这是可能的,这也明确了locmen Django的缓存后端)
- It is possible that you have some proxy server between your computer and the web server that is appropriately or inappropriately caching pages. Sometimes ISPs run proxy servers to reduce bandwidth outside their network. Can you please provide the HTTP headers for a page that is getting cached (Firebug can give these to you). Headers that I would specifically be interested in include Cache-Control, Expires, Last-Modified, and ETag.
- Can you post your MIDDLEWARE_CLASSES from your settings.py file. It possible that you have a Middleware that performs caching for you.
- Can you grep your code for the following items "load cache", "django.core.cache", and "cache_page". A *grep -R "search" ** will work.
- Does the settings.py (or anything it imports like "from localsettings import *") include CACHE_BACKEND?
- What happens when you restart apache? (e.g. sudo services apache restart). If a restart clears the issue, then it might be apache doing caching (it is possible that this could also clear out a locmen Django cache backend)
这篇关于如何禁用的Django / mod_wsgi的页面缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!