Author rhettinger
Recipients ncoghlan, rhettinger, serhiy.storchaka, thesheep
Date 2013-12-03.20:50:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I don't think this is an appropriate use of an LRU cache.  There are other ways to "freeze" a method return value (typically by storing the result in an instance).

Here's one way of doing it (taken from the source code for Itty ):

class lazyproperty(object):
    """A property whose value is computed only once. """
    def __init__(self, function):
        self._function = function

    def __get__(self, obj, _=None):
        if obj is None:
            return self
        value = self._function(obj)
        setattr(obj, self._function.func_name, value)
        return value

Here is how it is used:

class Request(object):
    """An object to wrap the environ bits in a friendlier way."""


    def POST(self):
        return self.build_complex_dict()

Date User Action Args
2013-12-03 20:50:13rhettingersetrecipients: + rhettinger, ncoghlan, serhiy.storchaka, thesheep
2013-12-03 20:50:13rhettingersetmessageid: <>
2013-12-03 20:50:13rhettingerlinkissue19859 messages
2013-12-03 20:50:13rhettingercreate