Skip to content

alanb43/memoizeK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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