Exceptions are cached?
See original GitHub issueHello,
I’m seeing some weird thing with Exception… The lru_cache decorator would not cache anything in case an exception is raised, so something like this:
# not very useful but shows well the difference
foo = 0
@lru_cache(maxsize=10)
def return_something_sync(a):
global foo
foo += 1
raise Exception(foo, time.time())
Would raise something like this:
return_something_sync(1)
>>> Exception: (1, 1564754537.844053)
return_something_sync(1)
>>> Exception: (2, 1564754539.949204)
So a new exception each time.
But with alru_cache, the exception itself is cached and raised back!
foo = 0
@alru_cache(maxsize=10)
async def return_something(a):
global foo
foo += 1
raise Exception(foo, time.time())
Will raise:
await return_something(1)
>>> Exception: (1, 1564754484.767096)
await return_something(1)
>>> Exception: (1, 1564754484.767096)
I would expect the exception not to be kept in cache, like for the sync equivalent; otherwise we have basically no way to call again the same function in case of transient issue (which can frequently happen if involving network access…).
Or am I missing something?
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
About caching exceptions | cruftex.net
The iteration of the cache entries, never throws an exception. Thus, the CacheEntry interface has the method getException() to check whether ...
Read more >Cache Exceptions | Apex Reference Guide
Cache Exceptions ; Cache.InvalidParamException, An invalid parameter value is passed into a method of Cache.Session or Cache.Org . This error occurs when: The ......
Read more >: Class CacheException - Oracle Help Center
CacheException is a generic exception, which indicates a cache error has occurred. All the other cache exceptions are the subclass of this class....
Read more >Cache Exception Handlers - Ehcache
Caches with ExceptionHandling configured are of type Ehcache. To get the exception handling behaviour they must be referenced using CacheManager.
Read more >Exceptions are cached? · Issue #162 · aio-libs/async-lru - GitHub
But with alru_cache , the exception itself is cached and raised back! ... I would expect the exception not to be kept in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Totally agree! Thank you for mentioning this parameter! 😃
This parameter (or at least this behaviour of caching exceptions) should be mentioned in the README!
OK… and then after I read the code, and see that there is a cache_exceptions option to turn that off!
Anyway, shouldn’t that option be False by default to be consistent with the sync version?