fix: passed 'args' and 'kwargs' are not considered when building a cache key
See original GitHub issueIf I am not wrong, this is a serious bug.
Problem
A function is cached always and only once, regardless of passed arguments.
import asyncio
from cashews import cache
cache.setup("mem://")
@cache(ttl="3h")
async def func(*args, **kwargs):
print(f"{args}; {kwargs}")
return args, kwargs
async def main():
await func("foo")
await func("bar")
await func("spam")
await func("eggs")
asyncio.run(main())
Result:
('foo',); {}
Expected result:
The function must be called on every unique args
and kwargs
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (4 by maintainers)
Top Results From Across the Web
python - Universal memoization decorator
I've just written a simple caching / memoization python decorator. It's purpose is to cache what the function returns for all the arguments...
Read more >Identifying equivalent varargs function calls for memoization
I'm wondering, is there a reasonable way to memoize based on both args and kwargs , particularly in cases where two function calls...
Read more >Key arguments in Apollo Client - Apollo GraphQL Docs
If a field has no arguments, its storage key is just its name. This default behavior is for safety: the cache doesn't know...
Read more >support python3 keyword-only arguments for function decorator
Basically, just treat any arg or kwarg as a named value as part of the cache key. Obviously this would increase key sizes,...
Read more >API — Flask Documentation (2.2.x)
If it has a provide_automatic_methods attribute, it is used as the default if the parameter is not passed. Parameters. rule (str) – The...
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
This is great, thanks a lot.
As I see , that is a very common thing to use *args **kwargs and developers expect that cache key will include these parameters.
So after 4.1.0 key will include disordered *args and ordered **kwargs