Skip to main content

Flexible caching utilities for Python functions

Project description

twat-cache

(work in progress)

A flexible caching utility package for Python functions that provides a unified interface for caching function results using various backends (memory, disk, SQL).

Features

  • Simple decorator interface for caching function results
  • Multiple caching backends:
    • Memory-based LRU cache (always available)
    • SQL-based disk cache using diskcache (optional)
    • Efficient array caching using joblib (optional)
  • Automatic cache directory management
  • Type hints and modern Python features

Installation

pip install twat-cache

Usage

Basic usage with default memory caching:

from twat_cache import ucache

@ucache()
def expensive_computation(x):
    # Results will be cached automatically
    return x * x

result = expensive_computation(42)  # Computed
result = expensive_computation(42)  # Retrieved from cache

Using SQL-based disk cache:

@ucache(folder_name="my_cache", use_sql=True)
def process_data(data):
    # Results will be cached to disk using SQL backend
    return data.process()

Using joblib for efficient array caching:

import numpy as np
from twat_cache import ucache

@ucache(folder_name="array_cache")
def matrix_operation(arr):
    # Large array operations will be efficiently cached
    return np.dot(arr, arr.T)

Cache Location

The package automatically manages cache directories using the following strategy:

  1. If platformdirs is available, uses the platform-specific user cache directory
  2. Otherwise, falls back to ~/.cache

You can get the cache path programmatically:

from twat_cache import get_cache_path

cache_dir = get_cache_path("my_cache")

Dependencies

  • Required: None (basic memory caching works without dependencies)
  • Optional:
    • platformdirs: For platform-specific cache directories
    • diskcache: For SQL-based disk caching
    • joblib: For efficient array caching

License

MIT License
.

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

twat_cache-1.7.5.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

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

twat_cache-1.7.5-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file twat_cache-1.7.5.tar.gz.

File metadata

  • Download URL: twat_cache-1.7.5.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for twat_cache-1.7.5.tar.gz
Algorithm Hash digest
SHA256 25cc3ab7c131cdf9fcd604d29224dafd056b5819a833e618689d54f3f2ee7020
MD5 a71be98ca85d197cd70f2d2e369ffaf2
BLAKE2b-256 7808d8fd04faae01bde5076b593fd4e9b84ef5655cf7497a7f59537a1c26d128

See more details on using hashes here.

File details

Details for the file twat_cache-1.7.5-py3-none-any.whl.

File metadata

  • Download URL: twat_cache-1.7.5-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for twat_cache-1.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7bed530ed6cc62a795408ab8d277d36fceb872d1921b3eeedc535f951d3b0ed5
MD5 7d8374f16d6dbec37b936d0bdfceead3
BLAKE2b-256 199b749bc5e695288437bfc8af96e5aeb8f3c2feae1bf94b4732241a1fd1f68f

See more details on using hashes here.

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