https://github.com/amandasaurus/django-default-dont-cache
Opt-in caching for Django's per-site cache.
https://github.com/amandasaurus/django-default-dont-cache
Last synced: 4 months ago
JSON representation
Opt-in caching for Django's per-site cache.
- Host: GitHub
- URL: https://github.com/amandasaurus/django-default-dont-cache
- Owner: amandasaurus
- License: gpl-3.0
- Created: 2013-08-21T09:49:53.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-21T09:50:12.000Z (almost 12 years ago)
- Last Synced: 2024-12-27T00:24:37.423Z (6 months ago)
- Language: Python
- Size: 113 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Opt-in caching for Django's per-site cache.
Django has a good 'whole page' caching system, the ['per-site' cache](https://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache). However it is "opt-out". By default all pages are cached, and you mark pages not to be cached with the ``@never_cache`` decorator.
This app turns that Django cache into a 'opt-in' cache. By default pages will *not* be cached, unless you use the ``@mark_for_caching`` decroator.
Installation
============pip install django-default-dont-cache
Usage
=====In your ``MIDDLEWARE_CLASSES`` setting:
MIDDLEWARE_CLASSES = (
…
'django.middleware.cache.UpdateCacheMiddleware',
…
'django.middleware.cache.FetchFromCacheMiddleware',
# This must be after the FetchFromCacheMiddleware
'default_dont_cache.middleware.DefaultDontCacheMiddleware',
…
)The ``DefaultDontCacheMiddleware`` *must* be after/below Django's ``FetchFromCacheMiddleware``.
By default none of your view will be cached by Django's caching system. You must manually whitelist views to be cached like so:
from default_dont_cache.decorators import mark_for_caching
@mark_for_caching
def myview(request):
…Now ``myview`` will be cached by the django caching system. Only views that have the ``@mark_for_caching`` decorator will be cached.
Licence & Copyright
===================© Rory McCann 2013, released under the GNU GPL v3 (or at your option a later verson). See the file LICENCE for more.