provides generic methods to memoize function and method calls
Project description
Memoi
Description
A generic caching mechanism for memoizing function or method calls.
Prerequisites
Python >= 3.10
Installation
python -m pip install memoi
Example
from datetime import datetime as dt
from memoi import cached, TextFileRepo
@cached(TextFileRepo('.'))
def f(*args, **kwargs):
return f"this is the result of the first f() call at {dt.now().isoformat()}"
print(f())
print(f())
This will create a a sqlite database memo.sqlite, keeping track of function calls, and a text file 50/506f353d3ef92d51f3e57bae99367caf directory, containing the result of the first f() call. Obviously the timestamp from the first function call is preserved.
Changelog
Release 0.0.1
Description
Minimum Viable Product of a result caching function decorator.
Added
decorator cached: providing a caching mechanism for return values, so the function is not executed the next time when it is called with the same arguments.
class TextFileRepo: for caching return values of functions returning strings as text files in a configurable directory.
Release 0.1.0
Description
Multi-String support.
Changed
cached: returns a pair of datetime and original result, the former indicating the date of first submission; can handle functions/methods that return iterables.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.