AccessTokenStore
public interface AccessTokenStore
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.
CachedAccessTokenio/agentscope/extensions/channel/common/AccessTokenStore.java:50put
public void put(CachedAccessToken token)
设置该参数。
Caches token, replacing any previous entry unconditionally.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
token | CachedAccessToken | 令牌到缓存。the token to cache |
io/agentscope/extensions/channel/common/AccessTokenStore.java:60putIfNewer
default public boolean putIfNewer(CachedAccessToken token)
设置该参数。
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.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
token | CachedAccessToken | 令牌(类型 `CachedAccessToken`)。the token to cache; the single-credential rule of `#put` applies |
booleanio/agentscope/extensions/channel/common/AccessTokenStore.java:74–81clear
public void clear()
清空或重置内部状态。
Drops the cached token so the owning provider fetches a fresh one on its next call.
io/agentscope/extensions/channel/common/AccessTokenStore.java:84