A Django-based convenience decorator for caching results of functions to various backends.
Project description
Django Function Cache
Cache the results of a function on S3 (and more!).
The function_cache
decorator enables flexibility in how cache key is generated.
Example
In your settings.py
, you can set up the FUNCTION_CACHE_BACKENDS
(defaults to S3FunctionCacheBackend
):
# Django Function Cache
# ---------------------
FUNCTION_CACHE_BACKENDS = {
'default': {
'BACKEND': 'function_cache.backends.S3FunctionCacheBackend',
'OPTIONS': {},
}
}
In your code, you can simply use the function_cache
decorator
from django.contrib.staticfiles.storage 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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for function_cache-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c565afb41854da8821ed9021b5b7cf58ff8d44d9b1b8450621017c069625ec4 |
|
MD5 | e5e32299b15790934cbb97ec1f5dd171 |
|
BLAKE2b-256 | 171ec275aff28b6e473057f72492b60d8fcb7ddb8f88476a5cfef6f084a58560 |