Metadata-Version: 2.4
Name: twat-cache
Version: 1.7.14
Summary: Flexible caching utilities for Python functions
Project-URL: Documentation, https://github.com/twardoch/twat-cache#readme
Project-URL: Issues, https://github.com/twardoch/twat-cache/issues
Project-URL: Source, https://github.com/twardoch/twat-cache
Author-email: Adam Twardoch <adam+github@twardoch.com>
License-Expression: MIT
License-File: LICENSE
Keywords: cache,decorator,disk-cache,joblib,memory-cache
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Requires-Python: >=3.10
Requires-Dist: diskcache>=5.0.0
Requires-Dist: joblib>=1.3.0
Requires-Dist: platformdirs>=4.0.0
Requires-Dist: twat>=1.0.0
Provides-Extra: all
Requires-Dist: diskcache>=5.0.0; extra == 'all'
Requires-Dist: joblib>=1.3.0; extra == 'all'
Requires-Dist: platformdirs>=4.0.0; extra == 'all'
Requires-Dist: twat>=1.0.0; extra == 'all'
Provides-Extra: dev
Requires-Dist: mypy>=1.0.0; extra == 'dev'
Requires-Dist: pre-commit>=3.6.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: test
Requires-Dist: pytest-benchmark[histogram]>=4.0.0; extra == 'test'
Requires-Dist: pytest-cov>=4.0.0; extra == 'test'
Requires-Dist: pytest-xdist>=3.5.0; extra == 'test'
Requires-Dist: pytest>=7.0.0; extra == 'test'
Description-Content-Type: text/markdown

# 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

```bash
pip install twat-cache
```

## Usage

Basic usage with default memory caching:

```python
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:

```python
@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:

```python
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:

```python
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  
.
