Class InMemoryTokenStore

java.lang.Object
cloud.opencode.base.oauth2.token.InMemoryTokenStore
All Implemented Interfaces:
TokenStore

public class InMemoryTokenStore extends Object implements TokenStore
In-Memory Token Store 内存 Token 存储

Thread-safe in-memory implementation of TokenStore.

TokenStore 的线程安全内存实现。

Features | 主要功能:

  • Thread-safe with ConcurrentHashMap - 使用 ConcurrentHashMap 线程安全
  • Fast access - 快速访问
  • No persistence - 无持久化

Usage Examples | 使用示例:

TokenStore store = new InMemoryTokenStore();

// Save token
store.save("user-1", token);

// Load token
Optional<OAuth2Token> loaded = store.load("user-1");

// Delete token
store.delete("user-1");

Thread Safety | 线程安全:

This class is thread-safe.

此类是线程安全的。

Since:
JDK 25, opencode-base-oauth2 V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • InMemoryTokenStore

      public InMemoryTokenStore()
      Create a new in-memory token store 创建新的内存令牌存储
  • Method Details

    • save

      public void save(String key, OAuth2Token token)
      Description copied from interface: TokenStore
      Save a token with the given key 使用给定的键保存令牌
      Specified by:
      save in interface TokenStore
      Parameters:
      key - the storage key | 存储键
      token - the token to save | 要保存的令牌
    • load

      public Optional<OAuth2Token> load(String key)
      Description copied from interface: TokenStore
      Load a token by key 通过键加载令牌
      Specified by:
      load in interface TokenStore
      Parameters:
      key - the storage key | 存储键
      Returns:
      the token if found | 找到的令牌
    • delete

      public void delete(String key)
      Description copied from interface: TokenStore
      Delete a token by key 通过键删除令牌
      Specified by:
      delete in interface TokenStore
      Parameters:
      key - the storage key | 存储键
    • deleteAll

      public void deleteAll()
      Description copied from interface: TokenStore
      Delete all stored tokens 删除所有存储的令牌
      Specified by:
      deleteAll in interface TokenStore
    • exists

      public boolean exists(String key)
      Description copied from interface: TokenStore
      Check if a token exists 检查令牌是否存在
      Specified by:
      exists in interface TokenStore
      Parameters:
      key - the storage key | 存储键
      Returns:
      true if exists | 存在返回 true
    • keys

      public Set<String> keys()
      Description copied from interface: TokenStore
      Get all stored keys 获取所有存储的键
      Specified by:
      keys in interface TokenStore
      Returns:
      the set of keys | 键集合
    • size

      public int size()
      Description copied from interface: TokenStore
      Get the number of stored tokens 获取存储的令牌数量
      Specified by:
      size in interface TokenStore
      Returns:
      the count | 数量
    • removeExpired

      public int removeExpired()
      Remove expired tokens 移除过期的令牌
      Returns:
      the number of tokens removed | 移除的令牌数量