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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file function-cache-0.2.0.tar.gz.
File metadata
- Download URL: function-cache-0.2.0.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c815ea196df163624c1ebdc557322feda248089b67ab29c5a09ae3d572f8f47d
|
|
| MD5 |
4f634fae49a403a42eac19ce7cba4e87
|
|
| BLAKE2b-256 |
74b5518264ac2b8cdd5b781ac4d56b4849d75f279c4f444a1d897d53f9adc058
|
File details
Details for the file function_cache-0.2.0-py3-none-any.whl.
File metadata
- Download URL: function_cache-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c565afb41854da8821ed9021b5b7cf58ff8d44d9b1b8450621017c069625ec4
|
|
| MD5 |
e5e32299b15790934cbb97ec1f5dd171
|
|
| BLAKE2b-256 |
171ec275aff28b6e473057f72492b60d8fcb7ddb8f88476a5cfef6f084a58560
|