A simple cache interface for Python objects. Abuse it.
There are many other caching libraries but this one is very minimal and it's meant to stay so.
Will add more documentation soon.
from mnemon import mnc
c = mnc()
c[0] = 1
print(c[0]) # returns 1 (obviously)
c.expire(0, 5) # expires in 5 seconds
del c[0]
Can be used in with
. (with mnc() as c: ...
). This has no effect on the
redis
backend.
from mnemon import mnd as mn
@mn
def f(x):
return x
- Default backend (
be
param to both mnc and mnd) isredis
. If Redis isn't found it will fall back to thefile
backend. - The
file
backend gets cleaned up every timemnc()
is called, or on__exit__
. - Caching by default pickles and compresses (
zlib
) the objects. Initialisingmnc
ormnc
withraw=True
bypasses pickling but assumes you're caching strings or bytes. Good to cache HTTP request results, bad for most other cases. Useraw
only with strings. - Compression is currently mandatory.
- For now nothing can be configured at runtime besides constructor parameters.