项目作者: zakuro-ai

项目描述 :
Zakuro module used to keep python scripts execution logs and results in a cached memory.
高级语言: Python
项目地址: git://github.com/zakuro-ai/zakuro-cache.git
创建时间: 2021-03-16T05:20:14Z
项目社区:https://github.com/zakuro-ai/zakuro-cache

开源协议:

下载


zakuro Logo


ZakuroCache is a Python package that provides two high-level features:

  • A simple decorator to identify the pure functions you want to cache.
  • A caching system that never repeat twice the same execution and return a cached result instead.

You can reuse your favorite Python packages such as NumPy, SciPy and Cython to extend ZakuroCache integration.

ZakuroCache modules

At a granular level, ZakuroCache is a library that consists of the following components:

Component Description
zakuro_cache Contains the implementation of the caching sytem.
zakuro_cache.loggers Keep the print into an array during the fuction execution.
zakuro_cache.function Pipeline to execute and store.

Installation

Docker

To build the image with docker-compose

  1. sh docker.sh

Local

  1. python setup.py install

Performances

If you are in local env you can run:

  1. python demo.py

You should be able to execute a benchmark:

  1. =====ZAKURO-CACHE=====
  2. 0.03user 0.00system 0:00.03elapsed 97%CPU (0avgtext+0avgdata 15444maxresident)k
  3. 0inputs+128outputs (0major+2493minor)pagefaults 0swaps
  4. =====NO-CACHE=====
  5. 10.18user 0.00system 0:10.18elapsed 99%CPU (0avgtext+0avgdata 15568maxresident)k
  6. 496inputs+128outputs (3major+2491minor)pagefaults 0swaps

Getting-started

To apply the cache simply add the decorator to your functions.

  1. from zakuro_cache.function import pure
  2. @pure
  3. def recur_fibo(n):
  4. if n <= 1:
  5. return n
  6. else:
  7. res1, res2 = recur_fibo(n - 1), recur_fibo(n - 2)
  8. return res1 + res2
  9. if __name__ == "__main__":
  10. nterms = 35
  11. for i in range(nterms):
  12. print(recur_fibo(i))