Set some cache-related headers automatically, defining not-authenticated
requests as public and authenticated requests as private. You can also customize these values for specific URLs. This middleware class will also setup these HTTP headers:
* Vary
* Cache-Control
* Expires
This middleware works and is designed to integrate Django with CloudFlare Cache (or similar services). Used in production on MinbilDinbil.dk servers.
## Installation
Add django-smartcc on your requirements.txt file or just launch:
pip install -U django-smartcc
Then add django-smartcc in the installed apps and in the middleware, so add these line in your settings.py file.
# settings.py
INSTALLED_APPS += [
'smart_cache_control',
]
MIDDLEWARE_CLASSES += [
'smart_cache_control.middleware.SmartCacheControlMiddleware'
]
**Note**: Remember that this middleware requires authentication, so it should be loaded after the *django.contrib.auth.middleware.AuthenticationMiddleware*!
## Customization and Settings
You can customize a specific Cache-control value on each URL. For example
if we want to avoid cache on */hello/* , but always have it on */api/search* for 5 minutes, we should write this in our settings file:
# settings.py
SCC_CUSTOM_URL_CACHE = (
(r'/hello/$', 'private', 0),
(r'/api/search$', 'public', 300),
)
Other options are available to customize the behaviour of the middleware:
**SCC_SET_VARY_HEADER**: Define if the middleware have to set the Vary header.
Default value: *True*
**SCC_SET_EXPIRE_HEADER**: Define if the middleware should set the Expires
header. Default value: *True*
**SCC_MAX_AGE_PUBLIC**: Define the default max-age value in seconds for public
requests. Default value: *86400*
**SCC_MAX_AGE_PRIVATE**: Define the default max-age value in seconds for
private requests. Default value: *0*
Metadata
Release files for django-smartcc 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-smartcc-0.1.2.tar.gz | 2.6 kB | Without provenance | Details for django-smartcc-0.1.2.tar.gz |
Release files / django-smartcc-0.1.2.tar.gz
| Download URL | django-smartcc-0.1.2.tar.gz |
|---|---|
| Size | 2.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1de253894e0cb32f04651cd193107bcdea82e6d4fd791e3797de75bcba325f58
|
|
BLAKE2b-256 checksum How to use checksums |
78cf68b694b9495db7904aa28304dc7d73ef0de299cc0b75d3c705d488a96eaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-smartcc 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.