Class SimpleTokenCache
The Simple Token Cache offers a basic in-memory token caching mechanism. It is designed to help improve performance and reduce the number of token requests made to Azure services during application runtime.
When using Azure services that require authentication, such as Azure Storage or Azure Key Vault, the library handles the acquisition and management of access tokens. By default, each request made to an Azure service triggers a token request, which involves authentication and token retrieval from the authentication provider (e.g., Azure Active Directory).
The Simple Token Cache feature caches the access tokens retrieved from the authentication provider in memory for a certain period. This caching mechanism helps reduce the overhead of repeated token requests, especially when multiple requests are made within a short time frame.
The Simple Token Cache is designed for simplicity and ease of use. It automatically handles token expiration and refreshing. When a cached token is about to expire, the SDK automatically attempts to refresh it by requesting a new token from the authentication provider. The cached tokens are associated with a specific Azure resource or scope and are used for subsequent requests to that resource.
Sample: Azure SAS Authentication
The following code sample demonstrates the creation of a SimpleTokenCache.
SimpleTokenCache simpleTokenCache =
new SimpleTokenCache(() -> {
// Your logic to retrieve access token goes here.
return Mono.just(new AccessToken("dummy-token", OffsetDateTime.now().plusHours(2)));
});
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleTokenCache(Supplier<Mono<AccessToken>> tokenSupplier) Creates an instance of RefreshableTokenCredential with default scheme "Bearer". -
Method Summary
Modifier and TypeMethodDescriptiongetToken()Asynchronously get a token from either the cache or replenish the cache with a new token.
-
Constructor Details
-
SimpleTokenCache
Creates an instance of RefreshableTokenCredential with default scheme "Bearer".- Parameters:
tokenSupplier- a method to get a new token
-
-
Method Details
-
getToken
Asynchronously get a token from either the cache or replenish the cache with a new token.- Returns:
- a Publisher that emits an AccessToken
-