AS AgentScopeAPI 手册 / API Reference

AccessTokenStore

public interface AccessTokenStore
源码Source io/agentscope/extensions/channel/common/AccessTokenStore.java:38–85

定义访问令牌存储契约的接口。位于 io.agentscope.extensions.channel.common 包。核心成员包括 get、put、putIfNewer、clear。

Caches the platform access token of one channel credential.

Channel token providers consult this store before fetching a token from the platform and write each fetched token back. The provider owns the policy — refresh timing, response parsing, and error-code invalidation — and treats the store as an opaque cache slot: one store instance serves one credential, and the store is not keyed, so an instance shared across providers built from different credentials would silently mix their tokens.

The default InMemoryAccessTokenStore keeps the token in the JVM heap, so it is not shared across processes. Deployments running multiple channel instances should provide an implementation backed by shared storage (for example Redis keyed by channel id) and inject it through the channel factories: one instance's refresh or invalidation then serves the whole deployment.

Implementations must be thread-safe: providers invoke these methods from concurrent reactive pipelines. Concurrent refreshes are expected (there is no cross-instance lock); providers store fetched tokens with #putIfNewer so racing refreshes cannot regress the cache to an earlier refresh deadline, while #put replaces unconditionally.

方法摘要Method Summary

方法Method说明Description
public CachedAccessToken get()
返回已缓存令牌。
Returns the cached token.
public void put(CachedAccessToken token)
设置该参数。
Caches `token`, replacing any previous entry unconditionally.
default public boolean putIfNewer(CachedAccessToken token)
default
设置该参数。
Caches `token` only when it is fresher than the entry currently held (strictly later `CachedAccessToken#refreshAtMs()`), so racing refreshes — expected, as there is no cross-instance lock — cannot pin an older token with an earlier deadline.
public void clear()
清空或重置内部状态。
Drops the cached token so the owning provider fetches a fresh one on its next call.

方法详情Method Detail

get

public CachedAccessToken get()

返回已缓存令牌。

Returns the cached token.

返回Returns CachedAccessToken
返回CachedAccessToken。the last stored token, or `null` when none is cached; entries are returned regardless of age — the owning provider applies the refresh deadline carried in `CachedAccessToken#refreshAtMs()`
源码Source io/agentscope/extensions/channel/common/AccessTokenStore.java:50

put

public void put(CachedAccessToken token)

设置该参数。

Caches token, replacing any previous entry unconditionally.

参数Parameters
名称Name类型Type说明Description
tokenCachedAccessToken令牌到缓存。the token to cache
源码Source io/agentscope/extensions/channel/common/AccessTokenStore.java:60

putIfNewer

default public boolean putIfNewer(CachedAccessToken token)
default

设置该参数。

Caches token only when it is fresher than the entry currently held (strictly later CachedAccessToken#refreshAtMs()), so racing refreshes — expected, as there is no cross-instance lock — cannot pin an older token with an earlier deadline.

参数Parameters
名称Name类型Type说明Description
tokenCachedAccessToken令牌(类型 `CachedAccessToken`)。the token to cache; the single-credential rule of `#put` applies
返回Returns boolean
返回布尔值,表示判断结果。`true` when `token` was stored
源码Source io/agentscope/extensions/channel/common/AccessTokenStore.java:74–81

clear

public void clear()

清空或重置内部状态。

Drops the cached token so the owning provider fetches a fresh one on its next call.

源码Source io/agentscope/extensions/channel/common/AccessTokenStore.java:84
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.