4 ms·
Beware lru_cache and mutable objects. I'm on a phone so this will probably contain an error but: @lru_cache def slow(): return {"result": "immu
by IanCal 7y ago
Beware lru_cache and mutable objects. I'm on a phone so this will probably contain an error but:
@lru_cache
def slow():
return {"result": "immutable?}
answer = slow()
answer["result"] = "no"
print(slow())
- IanCal 7y agoCan't edit now, but here's a runnable gist https://gist.github.com/IanCal/d703106344e876728d2aaef67800dfb8 https://gist.github.com/IanCal/d703106344e876728d2aaef67800d...
- andreareina 7y agoIt also won't let you cache on mutable values, so you can't pass in lists or dicts. I've used it on occasion, a lot of the time I ended up rolling my own instead. Usually without expiration since I didn't need it.