This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wdv4758h
Recipients wdv4758h
Date 2016-01-11.19:23:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1452540237.19.0.595360503064.issue26082@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2016-01-11 19:23:57wdv4758hsetrecipients: + wdv4758h
2016-01-11 19:23:57wdv4758hsetmessageid: <1452540237.19.0.595360503064.issue26082@psf.upfronthosting.co.za>
2016-01-11 19:23:57wdv4758hlinkissue26082 messages
2016-01-11 19:23:57wdv4758hcreate