A cache provider for CacheControl using Django's caching mechanism.
Project description
cachecontrol-django
A cache provider for CacheControl using Django's caching mechanism.
Installation
pip install cachecontrol-django
Usage
import requests
from cachecontrol import CacheControl
from cachecontrol_django import DjangoCache
session = CacheControl(requests.session(), cache=DjangoCache())
session.get("https://www.glassesdirect.co.uk/")
Working Around Key Length Errors
If you see errors about key length (such as "MemcachedKeyLengthError: Key length is > 250"), you can ask DjangoCache to hash the keys it uses by specifying a key_hash_algorithm
:
long_url = 'https://www.glassesdirect.co.uk/?q=' + ('x' * 250)
session = CacheControl(
requests.session(),
cache=DjangoCache(key_hash_algorithm='sha512')
)
session.get(long_url)
Note that when hashing these keys, there is a very small chance of a hash collision causing a request for one URL to return the content of another.
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
File details
Details for the file cachecontrol-django-1.0.0.tar.gz
.
File metadata
- Download URL: cachecontrol-django-1.0.0.tar.gz
- Upload date:
- Size: 2.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83ed784f09518de41022b2f1e71fdbfe12d498a041669fa1159c92e5b989476e |
|
MD5 | a35b0822440bea6228aa5537d5870390 |
|
BLAKE2b-256 | 8c0d2160703af69f8352d685a1c665eaf186fc5e2b27a7823be295a338939887 |