skillfed

django-cache-memoize

Django utility for a memoization decorator that uses the Django cache framework.

django-cache-memoize v0.2.1 248.2K downloads/30d#8,671 on PyPI169
Copyleft license MPL-2.0 Active released

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-memoize

uv

uv add django-cache-memoize

poetry

poetry add django-cache-memoize

Installing 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

Development Status :: 5 - Production/StableEnvironment :: Web Environment :: MozillaFramework :: DjangoIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseLicense :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)Programming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Internet :: WWW/HTTP

Tags

django function result cachingmemoization decorator djangocache decorator with timeoutdjango cache framework wrapperfunction call memoizationdjango performance optimizationcache invalidation decorator
django-cachingperformance-optimizationdecorator-pattern

More WWW/HTTP packages