Class InMemoryAccessTokenStore

java.lang.Object
io.agentscope.extensions.channel.common.InMemoryAccessTokenStore
All Implemented Interfaces:
AccessTokenStore

public final class InMemoryAccessTokenStore extends Object implements AccessTokenStore
In-process 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 Details

    • InMemoryAccessTokenStore

      public InMemoryAccessTokenStore()
  • Method Details

    • get

      public CachedAccessToken get()
      Description copied from interface: AccessTokenStore
      Returns 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:
      get in interface AccessTokenStore
      Returns:
      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()
    • put

      public void put(CachedAccessToken token)
      Description copied from interface: AccessTokenStore
      Caches token, 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:
      put in interface AccessTokenStore
      Parameters:
      token - the token to cache
    • putIfNewer

      public boolean putIfNewer(CachedAccessToken token)
      Description copied from interface: AccessTokenStore
      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.

      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:
      putIfNewer in interface AccessTokenStore
      Parameters:
      token - the token to cache; the single-credential rule of AccessTokenStore.put(io.agentscope.extensions.channel.common.CachedAccessToken) applies
      Returns:
      true when token was stored
    • clear

      public void clear()
      Description copied from interface: AccessTokenStore
      Drops the cached token so the owning provider fetches a fresh one on its next call.
      Specified by:
      clear in interface AccessTokenStore