Created
May 15, 2019 10:59
-
-
Save IanCal/d703106344e876728d2aaef67800dfb8 to your computer and use it in GitHub Desktop.
Be careful with lru_cache in python
This file contains hidden or 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
from functools import lru_cache | |
@lru_cache(1) | |
def cached(): | |
return ["Do cached entries safely return the same thing?"] | |
def uncached(): | |
return ["Do cached entries safely return the same thing?"] | |
cached_result = cached() | |
cached_result[0] = "no" | |
# You would want these to return the same thing | |
print(uncached(), cached()) | |
# Alas: | |
# > ['Do cached entries safely return the same thing?'] ['no'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment