+1 for vary_on_get, that fits nicely into the current scheme and just
sounds right to me.
bye, Georg
It is able to handle GET/POST parameters (via converting these
parameters to the array and futher hashing array to the string, which
will be used as an unique indentifier).
The remaining question is: What's the behavior if vary_on_get() isn't
specified for a particular view? Do we cache everything (including
separate cache entries for any combination of different GET
parameters) or cache nothing (current behavior)?
I have a couple of ideas for solutions. The first is to introduce a
NO_GET_PARAMS setting, which would default to False. If it's set to
True, Django would assume that *all* GET parameters (query strings),
sitewide, contain meaningless information, and therefore would not
account for them in creating cache. For example, a request to
example.com/foo/?bar=baz would use the same cache as example.com/foo/.
We might even be able to reuse this setting for other things; I'm not
sure what, yet.
On 6 Dec 2005, 15:37, Adrian Holovaty <holov...@gmail.com> wrote:
>
> The remaining question is: What's the behavior if vary_on_get() isn't
> specified for a particular view? Do we cache everything (including
> separate cache entries for any combination of different GETparameters) or cachenothing (current behavior)?
>
URL:s should be treated as opaque in the default behaviour so there
would be a separate cache entry for each of these:
example.com/list/
example.com/list/?a=1&b=2
example.com/list/?b=2&a=1
However, the developer may know better and details which parameters
that affect the get request. This could be provided in a decorator for
the view method like this:
Vary by the entire URL (should be default behaviour):
@cache_page(60 * 15)
@vary_by_param("*") #This should not be required to get per full URL
caching.
def slashdot_this(request):
...
Only vary by values for parameter a and b (ignore everything else):
@cache_page(60 * 15)
@vary_by_param(["a","b"])
def slashdot_this(request):
...
I have added this to ticket 4992 [1] as I believe it would be of great
benefit for everyone filtering lists of data by URL parameters (a
common use case).
Kind regards,
Peter Krantz
To be clear, the generated cache key would still include anything
stated in the HTTP Vary heads, right?
Vary: Cookie combined with @vary_on_get() should still vary on Cookie.
> The remaining question is: What's the behavior if vary_on_get() isn't
> specified for a particular view? Do we cache everything (including
> separate cache entries for any combination of different GET
> parameters) or cache nothing (current behavior)?
I say cache nothing; doing otherwise is backwards-incompatible. I
realize that means a bunch of decorators on views if you want the
cache-everything behavior.
Assuming vary_on_get() with no parameters means no variance (other
than the HTTP Vary headers), then
perhaps we could write a helper to walk URLConf and apply a
vary_on_get() decorator to indicate cache-everything. People could
opt-in this way without having to go update all code.
(This does fall down if you're mixing reusable apps that expect
cache-nothing. Hmm.)
@vary_on_get(None) ? :-)