Skip to main content

A disk-based caching utility for Python functions

Project description

dcache

A disk-based caching utility for Python functions.

Installation

pip install cache_on_disk

Usage

Basic Usage

from cache_on_disk import dcache

# For synchronous functions
@dcache
def expensive_function(x, y):
    # Some expensive computation
    return x + y

# For asynchronous functions
@dcache
async def async_expensive_function(x, y):
    # Some expensive async computation
    return x + y

With Required Arguments

You can specify which keyword arguments are required for caching:

@dcache(required_kwargs=["user_id"])
def get_user_data(user_id, include_history=False):
    # This will only be cached if user_id is provided as a keyword argument
    return {"user_id": user_id, "history": get_history(user_id) if include_history else None}

Custom Cache Configuration

from dcache import DCache

# Create a custom cache instance
my_cache = DCache(n_semaphore=50, cache_dir="/path/to/cache")

@my_cache
def my_function():
    # This will use the custom cache configuration
    pass

License

MIT

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

cache_on_disk-0.2.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

cache_on_disk-0.2.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file cache_on_disk-0.2.1.tar.gz.

File metadata

  • Download URL: cache_on_disk-0.2.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cache_on_disk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8ee4bf1171f9e98f3f4b18284a3f743c35f6d197ce4c9d40170fb6bf0af6cae6
MD5 2c91fc00dbd03e8b873655c5600afcbe
BLAKE2b-256 47043bd25c838555a09a41b27c293e5e3630cac4eb012c16641d3bb6ff663bda

See more details on using hashes here.

Provenance

The following attestation bundles were made for cache_on_disk-0.2.1.tar.gz:

Publisher: manual_publish.yaml on nielsrolf/dcache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cache_on_disk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: cache_on_disk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cache_on_disk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0790a03fc58b8f04a4e112284d64e33e34a456dddf5b69992bafab1411f9e2b
MD5 22ed7ab050901b86e66f5a08867cff28
BLAKE2b-256 45d1326df137f8e1d291651dfc37fe1c07df099b5f5d8330fd92f3880deda863

See more details on using hashes here.

Provenance

The following attestation bundles were made for cache_on_disk-0.2.1-py3-none-any.whl:

Publisher: manual_publish.yaml on nielsrolf/dcache

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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