sdispater / cachy

Cachy provides a simple yet effective caching library.
MIT License
42 stars 18 forks source link

Bug: The @cache decorator ignores the first argument of function call when generating a key #23

Open mraleson opened 2 years ago

mraleson commented 2 years ago

It looks like the @cache decorator ignores the first argument when generating a cache key. This led to a very confusing issue where some methods seemed to be cached correctly and some were incorrectly hashing to the same key and never being called.

It looks like this issue is from the _get_key function in repository.py:

        if args:
            serialized_arguments = (
                self._store.serialize(args[1:]) # <================= HERE ==============
                + self._store.serialize([(k, kwargs[k]) for k in sorted(kwargs.keys())])
            )

Perhaps this bug is because in the __call__ call function in cache_manager.py the store is already trimmed off args:

if len(args) > 0:
    store = args[0]
    args = args[1:] if len(args) > 1 else []
else:
    store = None