How to use it
--------------
-Define a class with an expensive property. Every time you stay there the
-price goes up by $50. I
+Let's define a class with an expensive property. Every time you stay there the
+price goes up by $50!
.. code-block:: python
.. code-block:: python
- >>> m = Monopoly()
- >>> m.boardwalk
+ >>> monopoly = Monopoly()
+ >>> monopoly.boardwalk
550
- >>> m.boardwalk
+ >>> monopoly.boardwalk
600
Let's convert the boardwalk property into a `cached_property`.
.. code-block:: python
- >>> m = Monopoly()
- >>> m.boardwalk
+ >>> monopoly = Monopoly()
+ >>> monopoly.boardwalk
550
- >>> m.boardwalk
+ >>> monopoly.boardwalk
550
- >>> m.boardwalk
+ >>> monopoly.boardwalk
550
Why doesn't the value of `m.boardwalk` change? Because it's a **cached property**!
* Django, Werkzueg, Bottle, and Zope for having their own implementations. This package uses the Django version.
* Reinout Van Rees for pointing out the cached_property decorator to me.
-* My awesome wife Audrey who created cookiecutter, which meant rolling this out took me just 15 minutes.
\ No newline at end of file
+* My awesome wife Audrey who created cookiecutter, which meant rolling this out took me just 15 minutes.