I re-post a question made to the django-users, I tried there first,
but I think is more development related.
I'm trying to use a the per view cache decorator cache_page, but I
have a multi-languaje site so the cache engine must generate its key
based on the page language. Using cache_page as is, doesn't work so my
idea is to use the vary headers decorator. I have added
patch_vary_headers(response,['Content-Language'])
to the views I want to caché, but without success, that is, whenever
the page is cached the first time in one language, you could change
the language but the cache returns the previous content.
Example:
I have accessed the page in spanish (es) and now I want to change to
catalan (ca). The response says
Content-Language ca
Content-Encoding gzip
Expires Sun, 09 Dec 2007 19:02:12 GMT
Vary Content-Language, Accept-Encoding, Accept-Language, Cookie
Last-Modified Sun, 09 Dec 2007 18:02:12 GMT
Etag 61c7f9e1202bd85458c7f8dc6df04ebd
Cache-Control max-age=3600
Content-Type text/html; charset=utf-8
but the page is still in spanish and it's not accessing to the view,
just taking the content from the caché.
By the way, I don't use the cache middleware.
It seems that the vary header should be the way to add the language to
the cache key, but I not able to make it work.
Any ideas?
I have a test project in http://code.google.com/p/appfusedjango/source
if somebody want's to play with it.
I have modified the django cache code to include the languaje code
when generating the key and it works as expected but this involves to
patch Django.
Language based caching is a common issue on multi-language site, so
perhaps this would be the default if i18n middleware is activated.
Best regards,
--
Antoni Aloy López
Binissalem - Mallorca
http://www.trespams.com
Soci de Bulma - http://www.bulma.cat