Configurable middleware to add HTTP caching headers for URL's.
Project description
Django Cache Headers
Overview
Django Cache Headers allows you to set HTTP caching headers for URL patterns according to certain policies. It does not perform any caching itself - it merely sets the headers on the response which are then interpreted by eg. Nginx.
Installation
Install or add django-cache-headers to your Python path.
Add cache_headers to your INSTALLED_APPS setting.
Add cache_headers.middleware.CacheHeadersMiddleware before SessionMiddleware and AuthenticationMiddleware to your MIDDLEWARE_CLASSES setting.
Policies
Django Cache Headers provides four caching policies. You may define your own policies.:
all-users - response is marked as cached once for all users.
anonymous-only - response is marked as cached once only for anonymous users.
anonymous-and-authenticated - response is marked as cached once for anonymous users and once for authenticated users.
per-user - response is marked as cached once for anonymous users and for each authenticated user individually.
Settings
The timeouts key combines the policy, timeout in seconds and URL regexes in a nested dictionary:
CACHE_HEADERS = { "timeouts": { "all-users": { 60: ( "^/all-users/", ) }, "anonymous-only": { 60: ( "^/anonymous-only/", ) }, "anonymous-and-authenticated": { 60: ( "^/anonymous-and-authenticated/", ) }, "per-user": { 60: ( "^/per-user/", ) }, "custom-policy": { 60: ( "^/custom-policy/", ) } } }
Changelog
0.1.2
Use the s-maxage header for compatability with Varnish.
0.1.1
Leave response untouched if status code is not 200.
0.1
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-cache-headers-0.1.2.tar.gz
.
File metadata
- Download URL: django-cache-headers-0.1.2.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 175fb4e45c4726955f1c1c82b51a60161bf88f8a42d5609f308da8d7387b5494 |
|
MD5 | 3b297d01583530f51ce7e80725fe3fab |
|
BLAKE2b-256 | 923551b8d1a6b049f3b5f08621549afa111a7ef82b344a3e77147becf7fb2a89 |
Provenance
File details
Details for the file django_cache_headers-0.1.2-py2.7.egg
.
File metadata
- Download URL: django_cache_headers-0.1.2-py2.7.egg
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a41a16a42efbc9ba9cae851977c7c40bb1a539e91a51dc107d3c283e3b4c516 |
|
MD5 | de5a6a4f7c13a4a97381cf8c0abcff42 |
|
BLAKE2b-256 | cd353fc755c6bd94913a9b9f86a1ecb9590648676fdc63bf4463c607f09a497d |