This PR introduces an enhanced default caching strategy for boto client instances within our AwsCredentials and MinIOCredentials classes.
We now cache boto client instances by default using Python's lru_cache mechanism, keyed on the credentials context (ctx) and client type.
The cache key is derived from a comprehensive hash of the credentials object, including fields like AWS access keys, secret access keys, session tokens, profile names, and region names, along with parameters specific to each client type.
The __hash__ method of AwsCredentials and MinIOCredentials is based on the combination of these fields, ensuring that any changes to the credentials object results in a different hash and thus a new cache entry.
Thread safety via a global lock (_LOCK), which synchronizes access to the get_client function, preventing race conditions in multi-threaded environments.
thanks to @mattiamatrix for doing the bulk of this work
closes #332
This PR introduces an enhanced default caching strategy for boto client instances within our
AwsCredentials
andMinIOCredentials
classes.lru_cache
mechanism, keyed on the credentials context (ctx
) and client type.__hash__
method ofAwsCredentials
andMinIOCredentials
is based on the combination of these fields, ensuring that any changes to the credentials object results in a different hash and thus a new cache entry._LOCK
), which synchronizes access to theget_client
function, preventing race conditions in multi-threaded environments.thanks to @mattiamatrix for doing the bulk of this work