Metadata-Version: 2.1
Name: tempcache
Version: 0.0.5
Summary: Python library to cache data and function results in temporary files
Project-URL: homepage, https://github.com/furechan/tempcache
Author-email: furechan <furechan@xsmail.com>
License: MIT License
License-File: LICENSE.txt
Keywords: command-line,utility
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Utilities
Requires-Python: >=3.8
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: cloudpickle; extra == 'dev'
Requires-Dist: invoke; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: toml; extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# Python library to cache data and function results in temporary files

This library offers a basic method to
cache data and functions to temporary files.
By default it will use the `pickle` module
to hash key values and to serialize data in temporary files.
It is meant to work with long running functions
whose results can be re-used. To avoid possible collisions
make sure to use a unique name when instantiating `TempCache`.


> **Note**
For more advanced use cases you may want to look at the `Memory` class
in [joblib](https://github.com/joblib/joblib).


## Basic Usage

An instance of the `TempCache` class be used as a decorator
to automatically cache the results of a function.

```python
from tempcache import TempCache

CACHE_MAX_AGE = 24 * 60 * 60 * 2    # two days
temp_cache = TempCache(__name__, max_age=CACHE_MAX_AGE)

@temp_cache
def long_running(...):
    ...

result = long_running(...)
```

## Caching results at the call site

You can also use a `TempCache` object to cache a result
at the call site with the `cache_result` method. 

```python
from tempcache import TempCache

CACHE_MAX_AGE = 24 * 60 * 60 * 2    # two days
temp_cache = TempCache(__name__, max_age=CACHE_MAX_AGE)

def long_running(...):
    ...

result = temp_cache.cache_result(long_running, ...)
```

## Advanced usage

In cases where the function or some of its arguments
are defined in the `__main__` namespace or in a jupyter notebook
and cannot be pickled by `pickle` you may want
to use a different pickle module like `cloupickle`.


```python
import cloudpickle

from tempcache import TempCache

CACHE_MAX_AGE = 24 * 60 * 60 * 2    # two days
temp_cache = TempCache("tempcache-foo",
                       pickler=cloudpickle,
                       max_age=CACHE_MAX_AGE)
```

## Examples

Examples notebooks are in the `extras` folder.

## Installation

You can install the latest version of this module with `pip`.

```console
python -mpip install git+https://github.com/furechan/tempcache.git
```

## Related Projects

- [joblib](https://github.com/joblib/joblib)
Computing with Python functions
- [cloudpickle](https://github.com/cloudpipe/cloudpickle)
Extended pickling support for Python objects

