Skip to main content

Quick and dirty caching of function results on disk using pickle

Project description

pklcache

The name stands for pickle cache, and it is a quick and dirty way of caching function results on disk using pickle.

This can be helpful for example in some machine learning tasks, where you have to preprocess the data with many time-consuming steps, and you want to not recompute things every time you run your program.

Example

from pklcache import cache

@cache("foo_result.pkl")
def foo(*args, **kwargs):
    # time consuming operations here...
    return result

If you run the program

result = foo()  #foo executed

And if you run it again

result = foo()  #foo not executed, load result from disk

The first time foo is called its result is saved on disk on foo_cache.pkl. If then the function is called another time or the program is run again, foo is not executed, instead its return value is loaded from disk and returned.

Args

@cache(fpath, enabled=True)

  • fpath: is the cache file path
  • enabled: if False the store/load is disabled and the function is executed like if it wasn't decorated. Useful during development and debugging.

Install

pip install pklcache

If you don't want an external dependency just copy and paste the code in __init__.py

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

pklcache-0.3.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

pklcache-0.3-py3-none-any.whl (4.3 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