From: Daniel Greenfeld Date: Fri, 13 Feb 2015 18:54:47 +0000 (-0800) Subject: Update README.rst X-Git-Tag: 1.0.0~3 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8e9063a0fc9189ea07834508ba8e6c80c47cb55c;p=cached-property.git Update README.rst --- diff --git a/README.rst b/README.rst index cac64d3..bbdb552 100644 --- a/README.rst +++ b/README.rst @@ -103,6 +103,37 @@ Results of cached functions can be invalidated by outside forces. Let's demonstr 600 >>> monopoly.boardwalk 600 + +Timing out the cache +-------------------- + +Sometimes you want the price of things to reset after a time. + +.. code-block:: python + + import random + from cached_property import cached_property + + class Monopoly(object): + + @cached_property(ttl=5) # cache invalidates after 10 seconds + def dice(self): + # I dare the reader to implement a game using this method of 'rolling dice'. + return random.randint(2,12) + +.. code-block:: python + + >>> monopoly = Monopoly() + >>> monopoly.dice + 10 + >>> monopoly.dice + 10 + >>> from time import sleep + >>> sleep(6) # Sleeps long enough to expire the cache + >>> monopoly.dice + 3 + >>> monopoly.dice + 3 Working with Threads ---------------------