Author wdv4758h
Recipients wdv4758h
Date 2016-01-11.19:23:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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):

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)


    @lru_cache(maxsize=None, cache=cache)
    def func(*args, **kwargs):
Date User Action Args
2016-01-11 19:23:57wdv4758hsetrecipients: + wdv4758h
2016-01-11 19:23:57wdv4758hsetmessageid: <>
2016-01-11 19:23:57wdv4758hlinkissue26082 messages
2016-01-11 19:23:57wdv4758hcreate