You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the @cached decorator, there's no problem in using it with different methods since it will create different prefixes based on the method signature.
I found a bit surprising that it's not the same for @multi_cached, this example will create clashing keys if the identifiers are the same:
@multi_cached('entity_ids', alias='default')asyncdefmulti1(self, entity_ids):
return {num: numfornuminentity_ids}
@multi_cached('entity_ids', alias='default')asyncdefmulti2(self, entity_ids):
return {num: num*2fornuminentity_ids}
# This worksassertawaitmulti1(entity_ids=[1, 2]) == {1: 1, 2: 2}
# This would fail, since it would return the cached results from the previous callassertawaitmulti2(entity_ids=[1, 2]) == {1: 2, 2: 4}
The text was updated successfully, but these errors were encountered:
In the case of cached, you are caching the function result while for multi_cached, you store each key from your entity_ids individually. The idea of this was that later in other parts of your code you could load those values easily doing cache.get('entity_id').
Yup, worth to add a warning in the documentation of multi_cached. Will leave this issue as reminder to do so
argaen
changed the title
@multi_cached decorator should use different prefixes by default
add warning in multi_cached docs about reusing keys
Mar 20, 2018
With the
@cached
decorator, there's no problem in using it with different methods since it will create different prefixes based on the method signature.I found a bit surprising that it's not the same for
@multi_cached
, this example will create clashing keys if the identifiers are the same:The text was updated successfully, but these errors were encountered: