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.4.0.tar.gz (5.4 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.4.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cache_on_disk-0.4.0.tar.gz
  • Upload date:
  • Size: 5.4 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.4.0.tar.gz
Algorithm Hash digest
SHA256 2454de6ada9facc7a900810cb65c6304b56ad9548df583ccc4f7c7e31d37871c
MD5 293da8e33513f6168e00869373da14ce
BLAKE2b-256 0f2e6299480e337c6f8fdb2cdb61c2d864fcc2ee3cc0de85992aca90f388be01

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: cache_on_disk-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d7503f6b18d0d439ae6f0985de0efdaa0cdad43dae01dc0c2e82595b079ae01
MD5 8ce9eb2d674a97bd9eb50b82b34f81c1
BLAKE2b-256 0c7dc82d834fe0c08bca82bd6563740159ecac82f988520234a44db2aad79891

See more details on using hashes here.

Provenance

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