https://github.com/atmb4u/cashier
Persistent caching for python functions
https://github.com/atmb4u/cashier
cache cashier functions persistent python python-functions python2 python3
Last synced: about 1 month ago
JSON representation
Persistent caching for python functions
- Host: GitHub
- URL: https://github.com/atmb4u/cashier
- Owner: atmb4u
- License: bsd-2-clause
- Created: 2017-03-25T19:45:44.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-07-01T14:04:43.000Z (almost 2 years ago)
- Last Synced: 2025-03-23T19:51:32.459Z (2 months ago)
- Topics: cache, cashier, functions, persistent, python, python-functions, python2, python3
- Language: Python
- Homepage: https://atmb4u.github.io/cashier
- Size: 13.7 KB
- Stars: 87
- Watchers: 6
- Forks: 9
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Cashier
-
_Persistent caching for python functions_Simply add a decorator to a python function and cache the results for future use. Extremely handy when you are dealing with I/O heavy operations which seldom changes or CPU intensive functions as well.
Anatomically, once a function is called, result from the function is cached into an SQLite3 database locally, with an expiry time. There is a maximum length for the cache to prevent cache flooding the file system.
Installation
-```pip install cashier```
Or you can clone the source and run setup.py
```bash
git clone [email protected]:atmb4u/cashier.git
cd cashier
python setup.py install
```Usage
-```python
from cashier import cache@cache()
def complex_function(a,b,c,d):
return complex_calculation(a,b,c,d)
```If you go ahead on the above configuration, following are the default values
* cache_file : `.cache`
* cache_time : `84600`
* cache_length : `10000`
* retry_if_blank : `False`Advanced Usage
-```python
from cashier import cache@cache(cache_file="sample.db", cache_time=7200, cache_length=1000,
retry_if_blank=True)
def complex_function(a, b, c, d):
return complex_calculation(a, b, c, d)
````cache_file` : SQLite3 file name to which cached data should be written into (defaults to .cache)
`cache_time` : how long should the data be cached in seconds (defaults to 1 day)
`cache_length` : how many different arguments and corresponding data should be cached (defaults to 10000)
`retry_if_blank` : If True, will retry for the data if blank data is cached ( default is `False`)
Performance Benchmark
-For reproducing results, run `python test.py` from the project root.
No Cache Run: **9.932126 seconds**
First Caching Run: **9.484081 seconds**
Cached Run: **0.606016 seconds (16 x faster)**