Skip to main content

cache functions output with auto refresh everytime you call it

Project description

functions cache

This library is inspired by requests-cache https://github.com/reclosedev/requests-cache and the whole engines code has been copied and modified from there.

this library provide a decorator that can be used to decorate your functions to be cached.

The main feature that diffentiate this library is that it will auto refresh the cache in a background thread so your cache will be kept fresh.

Sample code

from functions_cache import cache_it
import datetime



@cache_it
def fab_cached(n):
    if n < 2:
        return n
    else:
        return fab_cached(n-2)+fab_cached(n-1)

if __name__ == "__main__":
    t1 = datetime.datetime.now()
    print(fab_cached(100))
    t2 = datetime.datetime.now()
    print(t2-t1)
    t3 = datetime.datetime.now()
    print(fab_cached(100))
    t4 = datetime.datetime.now()
    print(t4-t3)
    

and the output

354224848179261915075
0:00:03.366472
354224848179261915075
0:00:00.014370

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

functions-cache-0.1.0.tar.gz (14.5 kB view hashes)

Uploaded Source

Built Distribution

functions_cache-0.1.0-py3-none-any.whl (15.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page