Skip to main content

Django Never Cache

This Django app provides a suite of utilities to disable caching in your views.

Requirements

  • Python >= 3.8
  • Django >= 3.2

Installation

  1. Install the package via pip:

    pip install django-never-cache
    
  2. Add django_never_cache to your INSTALLED_APPS in settings.py:

    INSTALLED_APPS = [
        ...
        "django_never_cache",
        ...
    ]
    

Usage

Mixins

NoCacheMixin

Use NoCacheMixin to disable caching for a view:

from django.views.generic import TemplateView
from django_never_cache.mixins import NoCacheMixin

class MyView(NoCacheMixin, TemplateView):
    template_name = "my_template.html"

PrivateAreaMixin

Use PrivateAreaMixin to require login and disable caching for a private area:

from django.views.generic import TemplateView
from django_never_cache.mixins import PrivateAreaMixin

class MyView(PrivateAreaMixin, TemplateView):
    template_name = "my_private_template.html"

NeverCacheMiddleware

Use NeverCacheMiddleware if you want to disable caching for the whole site:

MIDDLEWARE = [
    ...
    "django_never_cache.middlewares.NeverCacheMiddleware",
]

allow_cache

If you have added NeverCacheMiddleware to MIDDLEWARE, you can re-enable caching for a specific view using the allow_cache decorator:

from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
from django_never_cache.decorators import allow_cache

@method_decorator(allow_cache, name="dispatch")
class MyCachedView(TemplateView):
    template_name = "my_cached_template.html"

allow_cache supports both synchronous and asynchronous views.

Development

Prerequisites

  • tox
  • Golang >= 1.21

Run tests

To run the tests, run the following command:

tox

Contribute

You can contribute to this project on GitHub.

  1. Fork the repository.
  2. Create a new branch: git checkout -b my-branch-name.
  3. Install pre-commit with pre-commit install and make your changes.
  4. Commit your changes: git commit -am "Add some feature".
  5. Push your branch: git push origin my-branch-name.
  6. Create a pull request.

License

This project is released under the MIT License.

Download files

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

Source Distribution

django_never_cache-0.1.4.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_never_cache-0.1.4-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file django_never_cache-0.1.4.tar.gz.

File metadata

  • Download URL: django_never_cache-0.1.4.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_never_cache-0.1.4.tar.gz
Algorithm Hash digest
SHA256 249c8c7b9905bedd25cbc18fd569fec1626a598c4fbd4ecd44f1819d32842ee2
MD5 d8aaafc866798f7fb13b5cfd8cd536cb
BLAKE2b-256 dac794e860a08e2a9b8e2cf51783ee92e89c124bf7ea6bedd7aefe64593bdfad

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_never_cache-0.1.4.tar.gz:

Publisher: release.yml on trottomv/django-never-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_never_cache-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_never_cache-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bed676f0b1976cedbe1569419bb2c21bdb122c6bd5b40d30489d47877e1f1762
MD5 393205cd2420f60c2afecdccbe5a6b05
BLAKE2b-256 28acb8099e3949b392e2bbb2e9ca63d52475634453b5ead20a298f1cdb2b1d33

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_never_cache-0.1.4-py3-none-any.whl:

Publisher: release.yml on trottomv/django-never-cache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.5

2 files

This release

0.1.4 This release

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page