https://github.com/pierrekieffer/cache-operator
Provides simple caching method
https://github.com/pierrekieffer/cache-operator
cache-storage caching memoization memory python python-cache
Last synced: 3 months ago
JSON representation
Provides simple caching method
- Host: GitHub
- URL: https://github.com/pierrekieffer/cache-operator
- Owner: PierreKieffer
- License: bsd-2-clause
- Created: 2020-10-27T09:44:47.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-11-19T10:46:05.000Z (over 4 years ago)
- Last Synced: 2023-03-07T01:31:41.304Z (over 2 years ago)
- Topics: cache-storage, caching, memoization, memory, python, python-cache
- Language: Python
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cache-operator
![]()
cache-operator provides simple caching method.
Allows to cache the return values of a function depending on the arguments.
It can save time when an I/O bound function is periodically called with the same arguments.## Install
```bash
pip install .
```## Usage
```python
# import
from cache_operator import cache# call cache decorator
@cache
def worker(*args, **kwargs):
pass# To clean cache for associated method, call the method with clean_cache=True
```Example:
```python
from cache_operator import cache
import time@cache
def worker(i, k=2):
print("computing ...")
time.sleep(2)
return i*kif __name__=="__main__":
print("First run")
res = worker(1,2)
print(res)
print("------------")print("Second run")
res = worker(1,2)
print(res)print("------------")
print("Clean cache")
worker(clean_cache=True)
```Output :
```
First run
computing ...
2
------------
Second run
2
------------
Clean cache```