--- id: django-cache-memoize version: "0.2.1" license: MPL-2.0 license_treatment: copyleft maintenance: active --- # django-cache-memoize — Django utility for a memoization decorator that uses the Django cache framework. License: copyleft · Maintenance: active · Downloads: 248.2K/mo ## 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 above — 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 pip install django-cache-memoize uv add django-cache-memoize 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_current - Install friction: low - Maintenance: active - Downloads: 248.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django function result caching, memoization decorator django, cache decorator with timeout, django cache framework wrapper, function call memoization, django performance optimization, cache invalidation decorator, django-caching, performance-optimization, decorator-pattern [View on SkillFed](https://skillfed.io/packages/django-cache-memoize) · [View on PyPI](https://pypi.org/project/django-cache-memoize/)