-
Notifications
You must be signed in to change notification settings - Fork 173
Open
Description
When i specify key_builder for @multi_cached decorator, it makes two strange things: it modifies input for target function, and also return modified keys:
import asyncio
from aiocache import multi_cached
def key_builder(key, f, *args, **kwargs):
return key, args[0]
class MyClass:
@multi_cached(
keys_from_attr='ids',
key_builder=key_builder,
)
async def example(self, ids):
print('example called', ids)
return {id_: id_ for id_ in ids}
async def main():
obj = MyClass()
# {
# (1, <__main__.MyClass object at 0x10d1bf490>): (1, <__main__.MyClass object at 0x10d1bf490>),
# (2, <__main__.MyClass object at 0x10d1bf490>): (2, <__main__.MyClass object at 0x10d1bf490>)
# }
results = await obj.example(ids=[1, 2])
print(results)
asyncio.run(main())
I expect that this decorator at least should not change input parameters for target function. If i call MyClass().example(ids=[1,2]) i should get ids=[1,2] in my target function.
I also expected that result keys of function MyClass.example(ids=[1,2]) would also be unchanged - it is very confusing that decorator changes function result value. It should just perform caching.
Metadata
Metadata
Assignees
Labels
No labels