Skip to content

PierreKieffer/cache-operator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

pip install .

Usage

# 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:

from cache_operator import cache
import time

@cache
def worker(i, k=2): 
    print("computing ...")
    time.sleep(2)
    return i*k 

if __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

About

Provides simple caching method

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy