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.0.tar.gz (3.3 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.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cache_on_disk-0.2.0.tar.gz
  • Upload date:
  • Size: 3.3 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.0.tar.gz
Algorithm Hash digest
SHA256 6220b3e509fc40d3761d86da8f63a0a6b8e016e5a820a67791825915a2f7489d
MD5 28efaac92041a34805ef02401215754b
BLAKE2b-256 671fa7f7f9d53dd7aa4209ef8c6d5d2bef6e268a960f1d9e7999788dcc3192fd

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: cache_on_disk-0.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b88c1603fe9e7a444431138738929692a85da8c2cb47434489507b3f75863b9
MD5 f11500bd7c9e79b1030b4acdcf062cca
BLAKE2b-256 63d1928cb967e68a411f6ac877ed9398cdd00baf8eb1987a71e5f9430549d630

See more details on using hashes here.

Provenance

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