Skip to content

Instantly share code, notes, and snippets.

@IanCal
Created May 15, 2019 10:59
Show Gist options
  • Save IanCal/d703106344e876728d2aaef67800dfb8 to your computer and use it in GitHub Desktop.
Save IanCal/d703106344e876728d2aaef67800dfb8 to your computer and use it in GitHub Desktop.
Be careful with lru_cache in python
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