Skip to main content

Configurable middleware to add HTTP caching headers for URL's.

Project description

Django Cache Headers

Travis

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

  1. Install or add django-cache-headers to your Python path.

  2. Add cache_headers to your INSTALLED_APPS setting.

  3. 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.:

  1. all-users - response is marked as cached once for all users.

  2. anonymous-only - response is marked as cached once only for anonymous users.

  3. anonymous-and-authenticated - response is marked as cached once for anonymous users and once for authenticated users.

  4. 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/",
            )
        }
    }
}

Authors

Praekelt Consulting

  • Hedley Roos

Changelog

0.1.3

  1. Handle case where user may also be logged in and a cookie not being set.

0.1.2

  1. Use the s-maxage header for compatability with Varnish.

0.1.1

  1. Leave response untouched if status code is not 200.

0.1

  1. Initial release.

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-cache-headers-0.1.3.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

django_cache_headers-0.1.3-py2.7.egg (20.3 kB view details)

Uploaded Source

File details

Details for the file django-cache-headers-0.1.3.tar.gz.

File metadata

File hashes

Hashes for django-cache-headers-0.1.3.tar.gz
Algorithm Hash digest
SHA256 93ec498ff761a06932736d5e02fb02a28dd334f99aeb772347b786ca6d566bde
MD5 dc6d4b38d7a484cbbfd462ccc52465cd
BLAKE2b-256 107ed7ad112cb38699f37ffe76850cbb5ca9407f5960b17bc52f96db3e226c7c

See more details on using hashes here.

File details

Details for the file django_cache_headers-0.1.3-py2.7.egg.

File metadata

File hashes

Hashes for django_cache_headers-0.1.3-py2.7.egg
Algorithm Hash digest
SHA256 aa9ef5e74d0eaecce038319326b176d0d7ff9f0b9b00fa2a3ed9ff8b464ce618
MD5 92e1a1d85f3b5993f52d7799f9817264
BLAKE2b-256 dcd1d56ea3f53fe2599662707200a4ff3bc305cb47484db94dec93e3f7b719f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page