Message258001
Currently, lru_cache will automatically construct a Python dictionary in the function as cachedict. IMHO, it will be much more flexible to let users specified their cachedict, so they can use any kind of dict-like calss as their cachedict. Thus, users can use any dictionary implementation and save result in any form they want.
for example :
use OrderedDict
.. code-block:: python
from functools import lru_cache
from collections import OrderedDict
@lru_cache(maxsize=None, cache=OrderedDict())
def func(*args, **kwargs):
pass
save by pickle
.. code-block:: python
import os
import pickle
from functools import lru_cache
filename = "cache.pickle"
cache = {}
def load_cache():
global cache
if os.path.isfile(filename):
with open(filename, "rb") as f:
cache = pickle.load(f)
def store_cache():
with open(filename, "wb") as f:
pickle.dump(cache, f)
load_cache()
@lru_cache(maxsize=None, cache=cache)
def func(*args, **kwargs):
pass |
|
Date |
User |
Action |
Args |
2016-01-11 19:23:57 | wdv4758h | set | recipients:
+ wdv4758h |
2016-01-11 19:23:57 | wdv4758h | set | messageid: <1452540237.19.0.595360503064.issue26082@psf.upfronthosting.co.za> |
2016-01-11 19:23:57 | wdv4758h | link | issue26082 messages |
2016-01-11 19:23:57 | wdv4758h | create | |
|