https://github.com/danihodovic/django-disable-cache-headers
Middleware that disables caching headers during development in Django.
https://github.com/danihodovic/django-disable-cache-headers
cache-control context-processor django http-headers no-cache template
Last synced: 7 months ago
JSON representation
Middleware that disables caching headers during development in Django.
- Host: GitHub
- URL: https://github.com/danihodovic/django-disable-cache-headers
- Owner: danihodovic
- License: mit
- Created: 2019-08-22T14:38:12.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-22T22:07:38.000Z (almost 4 years ago)
- Last Synced: 2025-07-21T21:16:35.867Z (7 months ago)
- Topics: cache-control, context-processor, django, http-headers, no-cache, template
- Language: Python
- Homepage:
- Size: 11.7 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- Changelog: HISTORY.rst
- License: LICENSE
Awesome Lists containing this project
README
=============================
Django disable cache headers
=============================
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.
.. code-block:: python
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`:
.. code-block:: python
INSTALLED_APPS = (
...
'disable_cache_headers.apps.DisableCacheHeadersConfig',
...
)
Add the middleware in your development settings, e.g in config/settings/local.py.
.. code-block:: python
from .base import *
MIDDLEWARE += ["disable_cache_headers.middleware.DisableCacheControl"]
Running Tests
-------------
.. code-block:: bash
python -m venv venv
source ./venv/bin/activate
pip install -r requirements_test.txt
pytest