Class CachedFeatureStore
java.lang.Object
cloud.opencode.base.feature.store.CachedFeatureStore
- All Implemented Interfaces:
FeatureStore
Cached Feature Store with Optional Cache Module Delegation
支持可选缓存模块委托的缓存功能存储
Wraps another FeatureStore with caching for improved performance. If the Cache module (opencode-base-cache) is available, it delegates to OpenCache for high-performance caching. Otherwise, falls back to LruFeatureStore as cache.
用缓存包装另一个 FeatureStore 以提高性能。 如果缓存模块可用,则委托给 OpenCache 进行高性能缓存。 否则降级到使用 LruFeatureStore 作为缓存。
Usage Examples | 使用示例:
// Wrap a remote store with caching
FeatureStore remoteStore = new RedisFeatureStore(redisClient);
FeatureStore cachedStore = CachedFeatureStore.wrap(remoteStore);
// With custom TTL
FeatureStore cachedStore = CachedFeatureStore.wrap(remoteStore, Duration.ofMinutes(5));
// Check if cache module is available
boolean hasCache = CachedFeatureStore.isCacheModuleAvailable();
Features | 主要功能:
- TTL-based caching layer over any FeatureStore - 基于TTL的任意FeatureStore缓存层
- Automatic cache expiration and refresh - 自动缓存过期和刷新
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Null-safe: Partial (validates inputs) - 空值安全: 部分(验证输入)
- Since:
- JDK 25, opencode-base-feature V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all features 清除所有功能intcount()Get the count of features 获取功能数量booleanDelete a feature 删除功能booleanCheck if a feature exists 检查功能是否存在Find a feature by key 根据键查找功能findAll()Find all features 查找所有功能Gets the underlying delegate store.voidinvalidate(String key) Invalidates cache entry for a key.voidInvalidates all cache entries.static booleanChecks if the Cache module is available.booleanChecks if this store is using OpenCache.voidSave a feature 保存功能static CachedFeatureStorewrap(FeatureStore delegate) Wraps a feature store with caching.static CachedFeatureStorewrap(FeatureStore delegate, Duration ttl) Wraps a feature store with caching and custom TTL.static CachedFeatureStorewrap(FeatureStore delegate, Duration ttl, int maxSize) Wraps a feature store with caching and custom settings.
-
Method Details
-
isCacheModuleAvailable
public static boolean isCacheModuleAvailable()Checks if the Cache module is available. 检查缓存模块是否可用- Returns:
- true if Cache module is available | 如果缓存模块可用返回 true
-
wrap
Wraps a feature store with caching. 用缓存包装功能存储- Parameters:
delegate- the underlying store | 底层存储- Returns:
- cached feature store | 缓存的功能存储
-
wrap
Wraps a feature store with caching and custom TTL. 用缓存和自定义 TTL 包装功能存储- Parameters:
delegate- the underlying store | 底层存储ttl- the cache TTL | 缓存 TTL- Returns:
- cached feature store | 缓存的功能存储
-
wrap
Wraps a feature store with caching and custom settings. 用缓存和自定义设置包装功能存储- Parameters:
delegate- the underlying store | 底层存储ttl- the cache TTL | 缓存 TTLmaxSize- the maximum cache size | 最大缓存大小- Returns:
- cached feature store | 缓存的功能存储
-
save
Description copied from interface:FeatureStoreSave a feature 保存功能- Specified by:
savein interfaceFeatureStore- Parameters:
feature- the feature to save | 要保存的功能
-
find
Description copied from interface:FeatureStoreFind a feature by key 根据键查找功能- Specified by:
findin interfaceFeatureStore- Parameters:
key- the feature key | 功能键- Returns:
- optional containing feature if found | 如果找到则包含功能的Optional
-
findAll
Description copied from interface:FeatureStoreFind all features 查找所有功能- Specified by:
findAllin interfaceFeatureStore- Returns:
- list of all features | 所有功能的列表
-
delete
Description copied from interface:FeatureStoreDelete a feature 删除功能- Specified by:
deletein interfaceFeatureStore- Parameters:
key- the feature key | 功能键- Returns:
- true if deleted | 如果删除成功返回true
-
exists
Description copied from interface:FeatureStoreCheck if a feature exists 检查功能是否存在- Specified by:
existsin interfaceFeatureStore- Parameters:
key- the feature key | 功能键- Returns:
- true if exists | 如果存在返回true
-
count
public int count()Description copied from interface:FeatureStoreGet the count of features 获取功能数量- Specified by:
countin interfaceFeatureStore- Returns:
- feature count | 功能数量
-
clear
public void clear()Description copied from interface:FeatureStoreClear all features 清除所有功能- Specified by:
clearin interfaceFeatureStore
-
isUsingOpenCache
public boolean isUsingOpenCache()Checks if this store is using OpenCache. 检查此存储是否使用 OpenCache- Returns:
- true if using OpenCache | 如果使用 OpenCache 返回 true
-
invalidate
Invalidates cache entry for a key. 使键的缓存条目失效- Parameters:
key- the key to invalidate | 要使其失效的键
-
invalidateAll
public void invalidateAll()Invalidates all cache entries. 使所有缓存条目失效 -
getDelegate
Gets the underlying delegate store. 获取底层委托存储- Returns:
- the delegate store | 委托存储
-