Giter Club home page Giter Club logo

cache.py's Introduction

Cache

cache.py is a one file python library that extends memoization across runs using a cache file.

Often it takes some time to load files, do expensive data processing, and train models. As a result, many nice tools have popped up to make the experience smoother, like Jupyter notebooks. However, these tools make it hard to keep coding conventions clean and develop a library-like interface for your project.

cache.py attempts to make it painless to cache expensive functions across python runs, enabling quick iteration while developing usable code.

Usage

To use the file, import cache and annotate functions with @cache.cache().

import cache

@cache.cache()
def expensive_func(arg, kwarg=None):
  # Expensive stuff here
  return arg

The @cache.cache() function can take multiple arguments.

  • @cache.cache(timeout=20) - Only caches the function for 20 seconds.
  • @cache.cache(fname="my_cache.pkl") - Saves cache to a custom filename (defaults to hidden file .cache.pkl)
  • @cache.cache(key=cache.ARGS[KWARGS,NONE]) - Check against args, kwargs or neither of them when doing a cache lookup.

How it works

With a file loaded from disk, cache.py checks against the name, arguments and hash of a function's source to decide if the function has been run before. If it has it returns the cached result immediately. It currently uses pickle and inspect under the hood, making it non-portable.

cache.py's People

Contributors

bwasti avatar nicolascarpi avatar emgram769 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.