Skip to main content
added 17 characters in body
Source Link
Paulo Scardine
  • 78.2k
  • 12
  • 134
  • 153

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.

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 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.

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.

added 148 characters in body
Source Link
Paulo Scardine
  • 78.2k
  • 12
  • 134
  • 153

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 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.

You can write a custom middleware (untested, start with something like this and look at docs).

# my_middleware.py 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.

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 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.

Source Link
Paulo Scardine
  • 78.2k
  • 12
  • 134
  • 153

You can write a custom middleware (untested, start with something like this and look at docs).

# my_middleware.py 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.