Author rhettinger
Recipients jcea, rhettinger, serhiy.storchaka, steven.daprano
Date 2017-04-25.02:44:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
If you're interested, here is a starting point for experimenting with any variations you want (invalidate a specific entry, changeable maxsize, pickle/unpickle, expiration of entries after a specific time, inspection of the internal contents, ability to inject known values, testing whether a specific argument tuple is in the cache, logging of cache access, or just about anything you could do with a regular dictionary):

    class LRU(OrderedDict):

        def __init__(self, func, maxsize=128):
            self.maxsize = 128
            self.func = func

        def __call__(self, *args):
            if args in self:
                value = self[args]
                return value
            value = self.func(*args)
            if len(self) >= self.maxsize:
            self[args] = value
            return value
Date User Action Args
2017-04-25 02:44:34rhettingersetrecipients: + rhettinger, jcea, steven.daprano, serhiy.storchaka
2017-04-25 02:44:34rhettingersetmessageid: <>
2017-04-25 02:44:34rhettingerlinkissue30153 messages
2017-04-25 02:44:34rhettingercreate