Created
January 19, 2023 21:38
-
-
Save csparker247/dfdd83bae7e2b69d0d159f6b10f28ca3 to your computer and use it in GitHub Desktop.
Dynamically sized lru_cached function
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
import functools | |
class Foo: | |
@functools.lru_cache | |
def get(self, z): | |
return z | |
def set_cache_size(self, s): | |
Foo.get = functools.lru_cache(maxsize=s)(Foo.get.__wrapped__) | |
f = Foo() | |
f.get('a') | |
print(f.get.cache_info()) | |
f.set_cache_size(s=10) | |
print(f.get.cache_info()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment