Because built in Rust must mean it's blazingly fast... right?
Rust that compiles into a Python package that offers simple in-memoiry caching... or is it more like memoirization? 🤔 (Okay, I'll stop.)
import memoirs
@memoirs.Cache
def my_fancy_func(*args) -> str:
print('running')
return ' '.join(str(a) for a in args)
Once a function return is memoized, subsequent invocations return a cached result without running the function again.
>>> my_fancy_func('Hello', 'World!')
running
'Hello World!'
>>> my_fancy_func('Hello', 'World!')
'Hello World!'
For something more interesting (well, if you like basic arithmetic), take a look at this example.
To play around with it (please don't use this in prod):
1. Set up a virtual environment and install maturin
$ python -m venv .venv
$ source .venv/bin/activate
$ pip install maturin
$ maturin develop
There. Good to go.
This project is made possible by pyo3
. Check 'em out!!