Skip to main content
https://badge.fury.io/py/django-request-cache.svg https://github.com/anexia/django-request-cache/actions/workflows/test.yml/badge.svg?branch=main https://codecov.io/gh/anexia/django-request-cache/branch/main/graph/badge.svg

Django Request Cache provides a cache for each request (within your Django Request/Response cycle).

Quick start

  1. Download and install using pip install

pip install django-request-cache
  1. 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',
)
  1. 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

Metadata

Release files for django-request-cache 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-request-cache 1.5.0
File Size Uploaded
django-request-cache-1.5.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-request-cache 1.5.0
File Interpreter ABI Platform
django_request_cache-1.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.5 kB

Release files / django-request-cache-1.5.0.tar.gz

Download URL django-request-cache-1.5.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d4659cdc21afececa7e9f9c36afd252dfb189b43bc1af0b1916294deff7868c6
BLAKE2b-256 checksum
How to use checksums
e008a06444b95cd9fcd637f54a6a35e5c6e878cec0fd4b05b9287486dc10dbce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.18

Release files / django_request_cache-1.5.0-py3-none-any.whl

Download URL django_request_cache-1.5.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
31bf8109d260310e144f28f502f16ae0c1ab9bb6bd6ae3b7429cc3f587bb0bd8
BLAKE2b-256 checksum
How to use checksums
f10f43e799a7524be92137445b13b304b78908eb4bc8eeef65adeb2204a91eeb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.18

Release history Release notifications | RSS feed

This release

1.5.0 This release

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2

2 release files

1.1

1 release file

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page