Class InMemoryTokenStore
java.lang.Object
cloud.opencode.base.oauth2.token.InMemoryTokenStore
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidDelete a token by key 通过键删除令牌voidDelete all stored tokens 删除所有存储的令牌booleanCheck if a token exists 检查令牌是否存在keys()Get all stored keys 获取所有存储的键Load a token by key 通过键加载令牌intRemove expired tokens 移除过期的令牌voidsave(String key, OAuth2Token token) Save a token with the given key 使用给定的键保存令牌intsize()Get the number of stored tokens 获取存储的令牌数量
-
Constructor Details
-
InMemoryTokenStore
public InMemoryTokenStore()Create a new in-memory token store 创建新的内存令牌存储
-
-
Method Details
-
save
Description copied from interface:TokenStoreSave a token with the given key 使用给定的键保存令牌- Specified by:
savein interfaceTokenStore- Parameters:
key- the storage key | 存储键token- the token to save | 要保存的令牌
-
load
Description copied from interface:TokenStoreLoad a token by key 通过键加载令牌- Specified by:
loadin interfaceTokenStore- Parameters:
key- the storage key | 存储键- Returns:
- the token if found | 找到的令牌
-
delete
Description copied from interface:TokenStoreDelete a token by key 通过键删除令牌- Specified by:
deletein interfaceTokenStore- Parameters:
key- the storage key | 存储键
-
deleteAll
public void deleteAll()Description copied from interface:TokenStoreDelete all stored tokens 删除所有存储的令牌- Specified by:
deleteAllin interfaceTokenStore
-
exists
Description copied from interface:TokenStoreCheck if a token exists 检查令牌是否存在- Specified by:
existsin interfaceTokenStore- Parameters:
key- the storage key | 存储键- Returns:
- true if exists | 存在返回 true
-
keys
Description copied from interface:TokenStoreGet all stored keys 获取所有存储的键- Specified by:
keysin interfaceTokenStore- Returns:
- the set of keys | 键集合
-
size
public int size()Description copied from interface:TokenStoreGet the number of stored tokens 获取存储的令牌数量- Specified by:
sizein interfaceTokenStore- Returns:
- the count | 数量
-
removeExpired
public int removeExpired()Remove expired tokens 移除过期的令牌- Returns:
- the number of tokens removed | 移除的令牌数量
-