question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fix: passed 'args' and 'kwargs' are not considered when building a cache key

See original GitHub issue

If 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:closed
  • Created 2 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rkrellcommented, Mar 26, 2022

This is great, thanks a lot.

0reactions
Krukovcommented, Mar 26, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found