Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 863 Bytes

readme.md

File metadata and controls

30 lines (21 loc) · 863 Bytes

MemoizeK

An adjustable memoization library in Python that only caches the results from the K most recent arguments.

Rationale

I (@alanb43) got the inspiration from memoize-one in TypeScript, but I really wanted to use this as an excuse to learn about packages in python + getting a package on https://pypi.org/.

Usage

from memoizek import MemoizeK

def compute(func, *args):
    return func(*args)

def add(a,b):
    return a + b

memo_compute = MemoizeK(compute, 2) # remember 2 most-recent-calls' arguments
memo_compute(add, 1, 2) # registers a miss, returns 3
memo_compute(add, 1, 2) # registers a hit, returns cached value
memo_compute(add, 2, 1) # registers a miss, arguments don't match!

Installation

# pip / pip3
python3 -m pip install memoizek