Skip to content

Instantly share code, notes, and snippets.

@jcarlosroldan
jcarlosroldan / cache.py
Created July 24, 2018 11:40
Cache the result of any function
# -- the cache snippet ---------------------------------------------------------
from os import makedirs
from os.path import exists, dirname
from pickle import load as pload, dump as pdump
from re import sub
from time import time
def cache(target, args, identifier=None, cache_life=3 * 24 * 3600):
""" Run the target function with the given args, and store it to a pickled