I have a URL that returns the same content but with different templates depending on
request.is_ajax() value.
How can I include this in the cache’s key parameter, so I cache the correct response according to it?
I tried using vary_on_headers decorator with ‘XMLHttpRequest’, but it did not work.
Any ideas?
That’s because
vary_on_headersrequires you to specify the actual headers to check, and “XHMLHttpRequest” is not one of them. Django looks for that value in theHTTP_X_REQUESTED_WITHheader, so that’s the one you need to vary on.