Skip to main content

def-cache is a python package used to cache results from python methods

Project description

def-cache

PyPI Version Python Versions

def-cache is a python package that can be used as a method decorator to case their results.

Even though it can be used for any python method, it's aim is to be used in computational heavy methods, that do not need to be executed constantly and can be cached (eg: model training, heavy calculation tasks, etc)

Currently, the backend supported is fs (file-system) and the results of the cached method are stored in files

Installation

As def-cache is a python package it can be installed directly using pip:

python -m pip install def-cache

Alternatively one can use the source code directly.

Usage

Upon installation one can directly use the decorator on the methods that need to be cached.

A base usage example can be found below:

from def_cache import decorator

"""
The decorator below will cache the results of method: add for 60s in a file stored in the tmp relative path
"""


@decorator.cache(ttl=60, backend='fs', storage='tmp')
def add(x, y):
    return x + y


# this will not be called from cache
print(add(1, 2))

# this will be retrieved from cache
print(add(1, 2))

Example are also present in the examples directory.

Future Extensions

In the future we plan on adding storage engine support for the decorator, but of course would welcome any suggestions.

Download files

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

Source Distribution

def_cache-1.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

def_cache-1.0.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file def_cache-1.0.1.tar.gz.

File metadata

  • Download URL: def_cache-1.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for def_cache-1.0.1.tar.gz
Algorithm Hash digest
SHA256 97599cbef3870bf449bcac6e662d33d8307c5e1323c7d56268f8faa9928fcbd9
MD5 429bf8a7fa578f8fcda95c85e516321e
BLAKE2b-256 9991c8d16fa1641ca01cb230c755fd70a9587f090b3785cb944ff7b21f877b75

See more details on using hashes here.

File details

Details for the file def_cache-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: def_cache-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for def_cache-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 51c2a64d59715690e7f082c3695e53b87bf2e55f329954456c7a8fba7e85cc29
MD5 8562a4d054b428e959c9093a4e3c8930
BLAKE2b-256 5e6dd92cef5995ff5fe746434474494f4b43bc19cff5a19e93784c3e2bfb5f5f

See more details on using hashes here.

Supported by

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