diff --git a/aiocache/decorators.py b/aiocache/decorators.py index 114b22c2..d171bb3b 100644 --- a/aiocache/decorators.py +++ b/aiocache/decorators.py @@ -106,7 +106,7 @@ def get_cache_key(self, f, args, kwargs): if self.key: return self.key if self.key_builder: - return self.key_builder(*args, **kwargs) + return self.key_builder(f, *args, **kwargs) return self._key_from_args(f, args, kwargs) diff --git a/tests/acceptance/test_decorators.py b/tests/acceptance/test_decorators.py index 23921655..1b41bbda 100644 --- a/tests/acceptance/test_decorators.py +++ b/tests/acceptance/test_decorators.py @@ -41,15 +41,15 @@ async def fn(): @pytest.mark.asyncio async def test_cached_key_builder(self, cache): - def build_key(self, a, b): - return "{}_{}_{}".format(self, a, b) + def build_key(f, self, a, b): + return "{}_{}_{}_{}".format(self, f.__name__, a, b) @cached(key_builder=build_key) async def fn(self, a, b=2): return "1" await fn("self", 1, 3) - assert await cache.exists(build_key("self", 1, 3)) is True + assert await cache.exists(build_key(fn, "self", 1, 3)) is True class TestCachedStampede: