1@cache
2def factorial(n):
3 return n * factorial(n-1) if n else 1
4
5>>> factorial(10) # no previously cached result, makes 11 recursive calls
63628800
7>>> factorial(5) # just looks up cached value result
8120
9>>> factorial(12) # makes two new recursive calls, the other 10 are cached
10479001600
11