django-cache-memoize
Django utility for a memoization decorator that uses the Django cache framework.
What it is and what it does
django-cache-memoize is a lightweight decorator that wraps function calls and caches their results using Django's cache framework. It automatically generates cache keys from function arguments and keyword arguments, respecting a configurable timeout. The decorator works with Django's pluggable cache backends and handles pickling constraints transparently.
The package is designed for Django views and utility functions where repeated calls with the same arguments should return cached results. It offers advanced features like custom argument rewriting for complex objects, cache hit/miss callbacks for instrumentation, exception caching, and a guard mode that prevents repeated execution without storing results. The result must be pickleable to work with Django's cache framework.
Use it for:
- Cache expensive database queries in Django views to reduce load across repeated requests
- Memoize complex calculations in utility functions with automatic timeout-based invalidation
- Instrument cache performance by tracking hits and misses via callbacks for monitoring
- Prevent duplicate API calls or background jobs by using store_result=False as a guard
- Cache function results across multiple Django cache backends by specifying cache_alias
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A decorator that caches function results using Django's cache framework, with support for cache invalidation, custom argument rewriting, and hit/miss callbacks.
Yes, if you use Django and need simple function-level caching. The package is stable, actively maintained, has no external dependencies, and integrates cleanly with Django's cache framework. The MPL-2.0 copyleft license requires source disclosure if you modify and redistribute, but poses no restriction for typical use as a library dependency.
Install
django-cache-memoize on PyPI
pip
pip install django-cache-memoizeuv
uv add django-cache-memoizepoetry
poetry add django-cache-memoizeInstalling django-cache-memoize
Before you install
Low friction install with no runtime dependencies. Actively maintained with recent commits and a stable release history since 2017.
License in practice
Licensed under MPL-2.0, a copyleft license. You must disclose source code modifications and distribute under the same license if you modify and redistribute the package.
Quickstart
pip install django-cache-memoize
from django_cache_memoize import cache_memoize
@cache_memoize(100)
def expensive_function(start, end):
return sum(range(start, end))
result = expensive_function(0, 1000)
Requires Django to be installed and configured with a cache backend (e.g., memcached, Redis, or database cache).
Verify before relying
- Whether Django is an implicit peer dependency or if the decorator works outside Django projects
- Performance overhead of the decorator relative to direct cache calls
- Behavior when Django cache backend is not configured
Package facts
| License | MPL-2.0 (copyleft) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 604 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 248,224/month — #8,671 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_cache_memoize-0.2.1-py3-none-any.whl
Keywords: django, memoize, cache, decorator
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
django-memoizeCaches function and method results in Django…
permissive · top 15,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
py-memoizeCaching library for async Python applications…
permissive · top 15,000 on PyPI
cached_methodProvides a method-level caching decorator that…
permissive · top 15,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
django-cacheopsAutomatic and manual ORM query caching for…
permissive · top 5,000 on PyPI
cachetools-asyncProvides async-aware memoization decorators for…
permissive · top 15,000 on PyPI
cachierCachier is a decorator that adds persistent,…
permissive · top 15,000 on PyPI
django-cachalotAutomatically caches Django ORM queries and…
permissive · top 15,000 on PyPI
propcacheProvides fast cached-property decorators for…
permissive · top 100 on PyPI