Created
March 22, 2018 19:03
-
-
Save davesque/ecb581e81c880eb1aafdf46f821ac0b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Python 3.6.4 (default, Mar 14 2018, 11:02:01) | |
Type 'copyright', 'credits' or 'license' for more information | |
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help. | |
In [1]: from functools import lru_cache | |
In [2]: class Adder: | |
...: def __init__(self, n): | |
...: self.n = n | |
...: @lru_cache() | |
...: def add(self, x): | |
...: print('executing...') | |
...: return x + self.n | |
...: | |
In [3]: add1 = Adder(1) | |
In [4]: add2 = Adder(2) | |
In [5]: add1.add(1) | |
executing... | |
Out[5]: 2 | |
In [6]: add1.add(1) | |
Out[6]: 2 | |
In [7]: add2.add(1) | |
executing... | |
Out[7]: 3 | |
In [8]: add2.add(1) | |
Out[8]: 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment