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.5.0.tar.gz (5.5 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.5.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cache_on_disk-0.5.0.tar.gz
Algorithm Hash digest
SHA256 bc7f7102f9cf68a131824ee057ff94c3a38844d8ed3206f0451cf88f9ff2b06e
MD5 3871dd9ec9c9383a1014b275b6f31a0d
BLAKE2b-256 642818d83a0ff12c2494588f95369454b15153cfd1f0c8c688465a980f1c2669

See more details on using hashes here.

Provenance

The following attestation bundles were made for cache_on_disk-0.5.0.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.5.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for cache_on_disk-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 feb9e2dc96d2ed13b86ad77c540e8914713add383ceec267ece8cdc93b46f53d
MD5 390c1b17a9126dcf2c638a126818b0e9
BLAKE2b-256 799364eeacd80c4a6c0d25dc4124b6bd96db92c073b7f636b6d467048ce12aa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for cache_on_disk-0.5.0-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