flux.memoized_property module

flux.memoized_property.memoized_property(fget)

Return a property attribute for new-style classes that only calls its getter on the first access. The result is stored and on subsequent accesses is returned, preventing the need to call the getter any more.

Example

>>> class C(object):
...     load_name_count = 0
...     @memoized_property
...     def name(self):
...         "name's docstring"
...         self.load_name_count += 1
...         return "the name"
>>> c = C()
>>> c.load_name_count
0
>>> c.name
"the name"
>>> c.load_name_count
1
>>> c.name
"the name"
>>> c.load_name_count
1