Class InMemoryAccessTokenStore
- All Implemented Interfaces:
AccessTokenStore
AccessTokenStore holding a single token entry.
State lives in the JVM heap, so a token cached here is not visible to other instances; see
AccessTokenStore for multi-instance deployments. putIfNewer(io.agentscope.extensions.channel.common.CachedAccessToken) merges racing
stores atomically (freshest wins). This class is thread-safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Drops the cached token so the owning provider fetches a fresh one on its next call.get()Returns the cached token.voidput(CachedAccessToken token) Cachestoken, replacing any previous entry unconditionally.booleanputIfNewer(CachedAccessToken token) Cachestokenonly when it is fresher than the entry currently held (strictly laterCachedAccessToken.refreshAtMs()), so racing refreshes — expected, as there is no cross-instance lock — cannot pin an older token with an earlier deadline.
-
Constructor Details
-
InMemoryAccessTokenStore
public InMemoryAccessTokenStore()
-
-
Method Details
-
get
Description copied from interface:AccessTokenStoreReturns the cached token.The store holds the token of a single credential: sharing one instance across providers built from different credentials mixes their tokens.
- Specified by:
getin interfaceAccessTokenStore- Returns:
- the last stored token, or
nullwhen none is cached; entries are returned regardless of age — the owning provider applies the refresh deadline carried inCachedAccessToken.refreshAtMs()
-
put
Description copied from interface:AccessTokenStoreCachestoken, replacing any previous entry unconditionally.The store holds the token of a single credential: do not share one instance across providers built from different credentials.
- Specified by:
putin interfaceAccessTokenStore- Parameters:
token- the token to cache
-
putIfNewer
Description copied from interface:AccessTokenStoreCachestokenonly when it is fresher than the entry currently held (strictly laterCachedAccessToken.refreshAtMs()), so racing refreshes — expected, as there is no cross-instance lock — cannot pin an older token with an earlier deadline.The default implementation is a non-atomic read-compare-write; implementations backed by shared storage should override it with an atomic conditional write (for example a compare-and-set script) to keep the guarantee under concurrency.
- Specified by:
putIfNewerin interfaceAccessTokenStore- Parameters:
token- the token to cache; the single-credential rule ofAccessTokenStore.put(io.agentscope.extensions.channel.common.CachedAccessToken)applies- Returns:
truewhentokenwas stored
-
clear
public void clear()Description copied from interface:AccessTokenStoreDrops the cached token so the owning provider fetches a fresh one on its next call.- Specified by:
clearin interfaceAccessTokenStore
-