diff --git a/README.md b/README.md index 7b7ac2d..64847ad 100644 --- a/README.md +++ b/README.md @@ -621,6 +621,22 @@ def add(x, y): return x + y ``` +### LRU Cache +**Decorator that caches functions return values.** +```python +@lru_cache(maxsize=None) +def fib(n): + if n < 2: + return n + return fib(n-1) + fib(n-2) +``` + +```python +>>> [fib(n) for n in range(16)] +[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610] +>>> fib.cache_info() +CacheInfo(hits=28, misses=16, maxsize=None, currsize=16) +``` Class -----