I want to se the cache control to a higher number, instead of "no-store", which is the default for django.
Can I configure it in a way that's somewhat global?
You can write a custom middleware (untested, start with something like this and look at docs). It can save a lot of network resources for a site that gives pretty static information, like lottery results or historic stock quotes, for example.
# my_middleware.py
from django.conf import settings
# default 30 days
MAX_AGE = getattr(settings, 'CACHE_CONTROL_MAX_AGE', 2592000)
class MaxAgeMiddleware(object):
def process_response(self, request, response):
response['Cache-Control'] = 'max-age=%d' % MAX_AGE
return response
Append your middleware in settings.py MIDDLEWARE_CLASSES; middleware is like onion layers - order matters, during response phase first ones are processed last.
Set CACHE_CONTROL_MAX_AGE or any other parameter and give it a try.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With