Skip to content

Latest commit

 

History

23 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polycache

This Python package provides a simple decorator that allows you to cache the outputs of function calls to disk.

  1. Evaluate an expensive function once.
  2. Store its output on disk.
  3. Whenever the function is called again, retrieve the cached output from disk instead of evaluating it again.

Features

  • Simple to use: Apply a single decorator to your function to enable powerful caching
  • Native file formats: The outputs of functions are serialized to disk using native file formats.
  • Parameterizable: The filepaths where function outputs are saved can be parameterized by the function arguments.
    • For example, when add(x, y) is called with x=2 and y=3, its output can be automatically saved to x=2_y=3_output.pkl.
    • Nested directories are also possible: e.g. the same output could be saved to x=2/y=3/output.pkl.
  • Customizable: Keyword arguments can be passed to control the serialization/deserialization processes.
    • For example, if the function returns multiple numpy arrays (handled by numpy.savez internally), you could pass compress=True to enable compression.
  • Extensible: You can define custom save and load functions to use your own file formats.
  • Lazy: When supported by the file format, cached results are lazy-loaded by default to speed up the function call and save memory.

Acknowledgments

The initial inspiration for this decorator came from a similar implementation called result_caching used internally by the Brain-Score project. While this was handy, it was also rather inflexible, so I forked it and added features to support my use cases.

About

Cache function outputs to disk in a variety of native formats using a single flexible decorator (read-only mirror of https://codeberg.org/raj-magesh/polycache)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages