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 dcache

Usage

Basic Usage

from dcache 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.1.0.tar.gz (3.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.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cache_on_disk-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 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.1.0.tar.gz
Algorithm Hash digest
SHA256 01ee14702874fb067d84af862eb567de7d7439da2ca6ef29966cf1870709264c
MD5 4fb9c24943ecb1a1c95beb12b107fc2f
BLAKE2b-256 f4d0f6ebe3c1eddf5b7e382d2985eba982a6b3dfe9c7dd4277e482e1382328c3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: cache_on_disk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecf8453ac92b38cbae568a81fcdccd801fa4a37a647730e3225cf8c5e4804946
MD5 5c58972493528f5420b0f599731ecfd2
BLAKE2b-256 597d4f0292289bc5bc7df531163331fb38fbcfb5ca7dbabfcbb1da5c4ae37497

See more details on using hashes here.

Provenance

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