Skip to main content

Middleware that disables caching headers in Django

Project description

Middleware that disables caching headers during development in Django.

In production you will typically a CDN or browser cache to speed up subsequent reads of your pages. This ensures reads don’t need to hit your DB as often.

from django.views.decorators.cache import cache_control

@method_decorator(cache_control(public=True, max_age=60 * 5)), name="dispatch")
def my_view(request):
    ...

However this is annoying during development as you always want to serve fresh pages and static files on page refresh. Using this middleware in development strips out the cache headers and prevents the browser (or dev cache) from caching your content.

Quickstart

Install Django disable cache headers:

pip install django-disable-cache-headers

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'disable_cache_headers.apps.DisableCacheHeadersConfig',
    ...
)

Add the middleware in your development settings, e.g in config/settings/local.py.

from .base import *
MIDDLEWARE += ["disable_cache_headers.middleware.DisableCacheControl"]

Running Tests

python -m venv venv
source ./venv/bin/activate
pip install -r requirements_test.txt
pytest

History

0.1.0 (2019-08-22)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-disable-cache-headers-0.0.1.tar.gz (3.8 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page