django-memoize

raw JSON →
2.3.1 verified Fri May 01 auth: no python

An implementation of memoization technique for Django views and templates. Current version 2.3.1, with infrequent releases.

pip install django-memoize
error ImportError: No module named memoize
cause The package name is 'django-memoize' but the import module is just 'memoize'.
fix
Run 'pip install django-memoize' and then import as 'from memoize import memoize'.
gotcha The memoize decorator caches in process memory; for persistent caching across processes (e.g., with Redis or memcached) you need a different library or manual cache layer.
fix Use Django's cache framework directly if cross-process caching is required.
deprecated The library has not been updated in several years and may have compatibility issues with newer Django versions (3.x, 4.x, 5.x). Test thoroughly.
fix Consider using Django's built-in caching or other actively maintained memoization libraries.

Decorate a function with @memoize(seconds) to cache its result for the given number of seconds.

from memoize import memoize

@memoize(3600)
def expensive_function():
    return sum(i for i in range(1000000))