• Stars
    star
    111
  • Rank 314,510 (Top 7 %)
  • Language
    Python
  • Created almost 6 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python memoization across program runs.

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.

More Repositories

1

mebm

zero-dependency browser-based video editor
JavaScript
917
star
2

wasmblr

C++ WebAssembly assembler in a single header file
C++
164
star
3

jott

A simple way to jot down notes
JavaScript
111
star
4

vim-multiuser

a multiple user vim plugin
Python
105
star
5

emojicam

personal project to render webcam data directly as emoji πŸ˜ƒ
TypeScript
71
star
6

webpipe

A simple command line websocket utility for piping messages to and from a browser.
C
55
star
7

btb

Blue-text Bot AI. Uses Ollama + AppleScript
Python
49
star
8

pytorch_compiler_tutorial

Codebase associated with the PyTorch compiler tutorial
C++
44
star
9

mlvt

machine learning visualization tools in the terminal
Python
35
star
10

lazy

Python Library for Lazy Interfaces
Python
34
star
11

better_bindings

Better bindings for Python
Python
17
star
12

avalanche_playground

Structural (non-cryptographic) Python implementation of the Avalanche algorithm by TeamRocket
Python
15
star
13

torch_julia

[alpha] Expose Julia functions to PyTorch
C++
15
star
14

brr.js

trying to make WebGPU a bit easier to use
JavaScript
15
star
15

web_assembly_experiments

A repo to hold some simple experiments
C++
14
star
16

lofii

JavaScript
13
star
17

kayvee

model UI experiments
HTML
8
star
18

pic2emoji

convert images to emoji art
Python
7
star
19

bram.town

bram.town projects
TypeScript
5
star
20

webtorch

Python
3
star
21

template_array

Array manipulation at compile time.
C++
2
star
22

hma

lightweight differentiable multi-dimensional arrays
C++
1
star
23

evorati

Python
1
star
24

chess

C++
1
star
25

shumai_old

fast ML in JS with bun + flashlight
TypeScript
1
star
26

nnc_benchmark_server

Python
1
star
27

kq

C++
1
star
28

bison-example-calc-

hosting this -- from the bison gnu repo
C++
1
star