Skip to content

Python based decorators to take the drudgery out of executing function only when needed

License

Notifications You must be signed in to change notification settings

arunsundaram50/good-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

good_cache

good_cache is a Python library that caches the output of your functions. If your function has to read large files as its input or if it has to read files in a directory, and optionally some non-file function parameter values such as a str, int, bool, etc. values then good_cache can remember the input combination and return the ouput to the caller as long as the input combination has been seen (and cached) by good_cache previously.

Medium.com article that goes into some detail about good_cache:

GitHub repo:

pip command to install it:

pip install good_cache

A simple example of how you might use good_cache:

Sum up all the numbers in the given list of files

from good_cache import fs_files_cache

@fs_files_cache(files='filenames')
def sum_numbers_in_files(filenames):
    result = 0
    for filename in filenames:
        with open(filename, 'rt') as file:
            numbers = list(map(int, file.readlines()))
            result += sum(numbers)
    return result

total = sum_numbers_in_files(['a.txt', 'b.txt'])

You can evict (remove) a previous cache for a particular parameter(s)

evicted = sum_numbers_in_files.evict(['a.txt', 'b.txt'])

About

Python based decorators to take the drudgery out of executing function only when needed

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages