azure-docs-sdk-java/docs-ref-autogen/com.azure.core.credential.S...

52 строки
5.5 KiB
YAML

### YamlMime:JavaType
uid: "com.azure.core.credential.SimpleTokenCache"
fullName: "com.azure.core.credential.SimpleTokenCache"
name: "SimpleTokenCache"
nameWithType: "SimpleTokenCache"
summary: "The Simple Token Cache offers a basic in-memory token caching mechanism."
inheritances:
- "<xref href=\"java.lang.Object?displayProperty=fullName\" data-throw-if-not-resolved=\"False\" />"
inheritedClassMethods:
- classRef: "java.lang.<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html\">Object</a>"
methodsRef:
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--\">clone</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-\">equals</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--\">finalize</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--\">getClass</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--\">hashCode</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--\">notify</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--\">notifyAll</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--\">toString</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--\">wait</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-\">wait</a>"
- "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-\">wait</a>"
syntax: "public class **SimpleTokenCache**"
constructors:
- uid: "com.azure.core.credential.SimpleTokenCache.SimpleTokenCache(java.util.function.Supplier<reactor.core.publisher.Mono<com.azure.core.credential.AccessToken>>)"
fullName: "com.azure.core.credential.SimpleTokenCache.SimpleTokenCache(Supplier<Mono<AccessToken>> tokenSupplier)"
name: "SimpleTokenCache(Supplier<Mono<AccessToken>> tokenSupplier)"
nameWithType: "SimpleTokenCache.SimpleTokenCache(Supplier<Mono<AccessToken>> tokenSupplier)"
summary: "Creates an instance of Refreshable<wbr>Token<wbr>Credential with default scheme \"Bearer\"."
parameters:
- description: "a method to get a new token"
name: "tokenSupplier"
type: "<a href=\"https://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html\">Supplier</a>&lt;<a href=\"https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html\">Mono</a>&lt;<xref href=\"com.azure.core.credential.AccessToken?alt=com.azure.core.credential.AccessToken&text=AccessToken\" data-throw-if-not-resolved=\"False\" />&gt;&gt;"
syntax: "public SimpleTokenCache(Supplier<Mono<AccessToken>> tokenSupplier)"
desc: "Creates an instance of RefreshableTokenCredential with default scheme \"Bearer\"."
methods:
- uid: "com.azure.core.credential.SimpleTokenCache.getToken()"
fullName: "com.azure.core.credential.SimpleTokenCache.getToken()"
name: "getToken()"
nameWithType: "SimpleTokenCache.getToken()"
summary: "Asynchronously get a token from either the cache or replenish the cache with a new token."
syntax: "public Mono<AccessToken> getToken()"
desc: "Asynchronously get a token from either the cache or replenish the cache with a new token."
returns:
description: "a Publisher that emits an AccessToken"
type: "<a href=\"https://projectreactor.io/docs/core/release/api/reactor/core/publisher/Mono.html\">Mono</a>&lt;<xref href=\"com.azure.core.credential.AccessToken?alt=com.azure.core.credential.AccessToken&text=AccessToken\" data-throw-if-not-resolved=\"False\" />&gt;"
type: "class"
desc: "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.\n\nWhen 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).\n\nThe 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.\n\nThe 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.\n\n**Sample: Azure SAS Authentication**\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.core.credential.SimpleTokenCache\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.core.credential.SimpleTokenCache\"></xref>.\n\n```java\nSimpleTokenCache simpleTokenCache =\n new SimpleTokenCache(() -> {\n // Your logic to retrieve access token goes here.\n return Mono.just(new AccessToken(\"dummy-token\", OffsetDateTime.now().plusHours(2)));\n });\n```"
metadata: {}
package: "com.azure.core.credential"
artifact: com.azure:azure-core:1.54.0