[patch] caching needs to take more into account than just the URL
|Reported by:||hugo||Owned by:||Adrian Holovaty|
|Component:||Core (Cache system)||Version:|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
currently the cache key for the caching middleware and the caching decorator takes into account the prefix, the URL and wether gzip is required or not. This needs to be extended to take into account the cookies and the Http-accept-language header (for i18n). The reason is that programmers will base content of views on the content of cookies or session data (that itself is referenced as the session id by some cookie) and so the caching middleware would deliver a personalized page to some different user.
The attached patch works in that it builds the cache key out of the URL and some HTTP headers by creating a md5 hexdigest. There is one problem with this: you get less false cache hits, but you get less cache hits in all: if two users would see the same page because it's content isn't cookie based, but have different cookie settings nonetheless, they will occupy two cache slots. But the current solution isn't right, so maybe we have to live with the less cache hits - it's a standard problem of caching, anyway.
This is similar to the HTTP caching like is done by squid: there you have to mark your pages with the Varying header to define what HTTP headers should be taken into account when building the cache key. So maybe a more involved solution might be to require the programmer to set attributes on view functions that define the HTTP headers to take into account when caching. That way it's up to the programmer to define wether his view is based on cookie data or i18n language selection.
This more involved version could accumulate the cache-key relevant headers in the request - that way middleware can add headers to be taken into account and so the cache key creation will be fully based on both view functions and middleware.
Change History (13)
comment:8 Changed 11 years ago by
|Owner:||changed from hugo to Adrian Holovaty|
|Status:||new → assigned|