I'm implementing a small "persistent" version of functools.lru_cache, where "persistent" means that the cache is not destroyed between subsequent runs. To this end, I thought I could simply replace the dictionary that functools.lru_cache
uses by a shelve object, but I'm running into shelve
s requirement for keys to be str
ings. I tried to fix it by using str(hash(...).to_int(...))
, but hash(...)
is not identical for identical objects between different runs of the cpython interpreter.
Is there any class like shelve
that allows for any hashable key, rather than just str
ings, while being accessible like a dictionary transparently?
Some details: my cache might be in the order of 100MB. It is somewhat frequently read and infrequently written.