A simple Django app that provides a per-request cache.
Project description
Django Request Cache provides a cache for each request (within your Django Request/Response cycle).
Quick start
Download and install using pip install
pip install django-request-cache
Add UserForeignKeyMiddleware and RequestCacheMiddleware to your MIDDLEWARE settings like this:
MIDDLEWARE = (
...
'django.contrib.auth.middleware.AuthenticationMiddleware',
...
'django_userforeignkey.middleware.UserForeignKeyMiddleware',
'django_request_cache.middleware.RequestCacheMiddleware',
)
or if you are still using the an older Django version (e.g., Django 1.8) with MIDDLEWARE_CLASSES:
MIDDLEWARE_CLASSES = (
...
'django.contrib.auth.middleware.AuthenticationMiddleware',
...
'django_userforeignkey.middleware.UserForeignKeyMiddleware',
'django_request_cache.middleware.RequestCacheMiddleware',
)
Use the per-request cache as a decorator
from django_request_cache import cache_for_request
@cache_for_request
def do_some_complex_calculation(a, b, c):
print("Calculating... please wait")
return a * b * c
Try it out by executing do_some_complex_calculation multiple times within your request
Attribution
RequestCache and RequestCacheMiddleware (see middleware.py) are from a source code snippet on StackOverflow https://stackoverflow.com/questions/3151469/per-request-cache-in-django/37015573#37015573 created by coredumperror https://stackoverflow.com/users/464318/coredumperror Original Question was posted by https://stackoverflow.com/users/7679/chase-seibert at https://stackoverflow.com/questions/3151469/per-request-cache-in-django copied on 2017-Dec-20
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
Built Distribution
File details
Details for the file django-request-cache-1.5.0.tar.gz
.
File metadata
- Download URL: django-request-cache-1.5.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d4659cdc21afececa7e9f9c36afd252dfb189b43bc1af0b1916294deff7868c6
|
|
MD5 |
81781e8dbca37b91287d704a6d8d0f32
|
|
BLAKE2b-256 |
e008a06444b95cd9fcd637f54a6a35e5c6e878cec0fd4b05b9287486dc10dbce
|
File details
Details for the file django_request_cache-1.5.0-py3-none-any.whl
.
File metadata
- Download URL: django_request_cache-1.5.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.8.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
31bf8109d260310e144f28f502f16ae0c1ab9bb6bd6ae3b7429cc3f587bb0bd8
|
|
MD5 |
2f3d59dc8f6c7a384d6aa48f797a8aaa
|
|
BLAKE2b-256 |
f10f43e799a7524be92137445b13b304b78908eb4bc8eeef65adeb2204a91eeb
|