Skip to main content

A Django-based convenience decorator for caching results of functions to various backends.

Project description

Django Function Cache

PyPI version PyPI django version PyPI license PyPI pyversions PyPI status PyPI download total

Cache the results of a function on S3 (and more!). The function_cache decorator enables flexibility in how cache key is generated.


In your, you can set up the FUNCTION_CACHE_BACKENDS (defaults to S3FunctionCacheBackend):

# Django Function Cache
# ---------------------
    'default': {
        'BACKEND': 'function_cache.backends.S3FunctionCacheBackend',
        'OPTIONS': {},

In your code, you can simply use the function_cache decorator

from import staticfiles_storage
from function_cache.decorators import function_cache

@function_cache(name='default', keys=('args[0]', 'args[1]', 'k'), storage=staticfiles_storage)
def create_dict(a, b, k=None, _cache_key=None):
    print(f'The cache key is <{_cache_key}>.')
    return dict(a=a, b=b, k=k)
#end def

def run():
    x = create_dict('variable a', 'b', k={'keyword argument': 42})
#end def

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

function-cache-0.2.0.tar.gz (3.8 kB view hashes)

Uploaded Source

Built Distribution

function_cache-0.2.0-py3-none-any.whl (5.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page