lonelyenvoy / python-memoization

A powerful caching library for Python, with TTL support and multiple algorithm options.
MIT License
230 stars 15 forks source link

Idempotent cache key for function kwargs regardless of their order #6

Closed goredar closed 4 years ago

goredar commented 4 years ago

Hi, there.

Currently, there is a cache miss when the order of function kwargs is not preserved during several calls. Tried to fix this behavior.

Looking forward to your reply.

lonelyenvoy commented 4 years ago

Hi Vitaliy,

Thanks for your contribution. Your solution works well!

The only drawback is that the sorting will slow down the make_key function a little bit (~10%). Since it is not a common practice to call a function multiple times with its kwargs in different order, I will add an option to the @cached decorator so that users can decide whether they need this feature.

Cheers!

goredar commented 4 years ago

Thanks a lot!