I've found a small discrepancy between cachetools.cahcmethod and asyncache.cachemethod behavior in regards of default key function. Perhaps it makes sense to use keys.methodkey instead of keys.hashkey there to exclude self being used for cache keys?
This would neglect the requirement of a class instance to be hashable and overall just looks like a better way of caching instance method calls.
I don't have access to create PRs myself, here is the change snippet:
--- a/asyncache/__init__.py
+++ b/asyncache/__init__.py
@@ -117,7 +117,7 @@ def cachedmethod(
cache: Callable[[Any], Optional[MutableMapping[_KT, Any]]],
# ignoring the mypy error to be consistent with the type used
# in https://github.com/python/typeshed/tree/master/stubs/cachetools
- key: Callable[..., _KT] = keys.hashkey, # type:ignore
+ key: Callable[..., _KT] = keys.methodkey, # type:ignore
lock: Optional[Callable[[Any], "AbstractContextManager[Any]"]] = None,
Hello!
I've found a small discrepancy between
cachetools.cahcmethod
andasyncache.cachemethod
behavior in regards of defaultkey
function. Perhaps it makes sense to usekeys.methodkey
instead ofkeys.hashkey
there to excludeself
being used for cache keys? This would neglect the requirement of a class instance to be hashable and overall just looks like a better way of caching instance method calls.I don't have access to create PRs myself, here is the change snippet: