-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhanced cache access API for functools.lru_cache #54795
Comments
As per private email to Raymond, I would like to move the lru_cache access attributes and methods into a CacheInfo class, exposed as a "cache" attribute with several methods and read-only properties. Read-only properties: hits, misses, maxsize As an implementation detail, cache_misses and cache_hits become nonlocal variables rather than attributes of the wrapper function. Priority set to high, since the current API will be locked in as soon the first beta goes out. |
Raymond suggested a simple cache_info() method that returns a named tuple as a possible alternative. I like that idea, as it makes displaying debugging information (the intended use case for these attributes) absolutely trivial: >>> import functools
>>> @functools.lru_cache()
... def f(x):
... return x
...
>>> f.cache_info()
lru_cache_info(maxsize=100, currsize=0, hits=0, misses=0) (Alternative patch attached) |
Okay, go ahead with the second patch. _CacheInfo = namedtuple("CacheInfo", "maxsize size hits misses") Change the variable names: Add a "with lock:" to the cache_info() function. Update the docs. Thanks. |
Committed in r86878. I put a XXX note in the relevant part of the 3.2 What's New rather than updating it directly. |
Thx |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: