This site is an archive; learn more about 8 years of OpenHatch.

[OH-Dev] [issue565] Use cache-control headers so that anonymous pages are always cached by reverse proxies

Asheesh Laroia bugs at openhatch.org
Mon Aug 22 22:55:57 UTC 2011


New submission from Asheesh Laroia <asheesh at asheesh.org>:

Right now, we rely on Django's caching for performance. We use the django-
staticgenerator app to do some ad-hoc extra caching.

There are some pages which are accessed by users who are logged-in that we should 
be able to cache. Right now, if a request gets passed all the way to Django, we 
have Django generate the results.

But that is not the only way to do it. Instead, Django could simply indicate that 
the request has not been modified in the time since it was last cached.

The way this would work is:

* First time: Client connects to our transparent proxy and does a GET. Proxy has 
no data in the cache, so it asks the Django code. Our Django code returns the 
full response, as well as this HTTP header: "Cache-control: public, s-maxage=0, 
proxy-revalidate".

* Second time: Client connects to our transprent proxy and does a GET. Proxy has 
the page in its cache. Because the Django app said 'proxy-revalidate', the proxy 
must always ask the server if the cached version is valid. The proxy does the 
GET, but also adds a header: "If-Modified-Since:" plus the time that it did the 
GET that caused the data to be in the cache. Django app looks at all the models 
that it would have used, and if none were modified since the If-Modified-Since 
time, it says, "304 Not Modified". This is way faster than actually generating 
the page.

Thanks to Michael Stone for this concept.

----------
keyword: performance
messages: 2372
milestone: 0.11.09
nosy: paulproteus
priority: bug
status: unread
title: Use cache-control headers so that anonymous pages are always cached by reverse proxies

__________________________________________
Roundup issue tracker <bugs at openhatch.org>
<https://openhatch.org/bugs/issue565>
__________________________________________


More information about the Devel mailing list