django-elephant

A simple cache for Django functions and methods


Keywords
django, cache
License
MIT
Install
pip install django-elephant==1.0.0

Documentation

django-elephant

Build Status PyPI version codecov.io Code Issues

django-elephant is a simple wrapper to cache responses of Django methods or functions

Setup

pip install django-elephant

Usage

Basic:

from elephant import memorize

@memorize()
def foo(bar):
    return bar

Set cache configuration:

from django.core.cache import caches
from elephant import memorize

other_cache = caches['other_cache']

@memorize(
    cache=other_cache
)
def foo(bar):
    return bar

Set cache timeout:

from elephant import memorize

@memorize(
    timeout=1987
)
def foo(bar):
    return bar

Set cache key:

from elephant import memorize

def my_custom_key(function, *args, **kwargs):
    return '{}.{}'.format(
        'elephant_'
        function.__name__
    )

@memorize(
    cache_key=my_custom_key
)
def foo(bar):
    return bar

Requirements

  • Django>=1.5

Contribute

  • Fork and make a pull request!