Class LruFeatureStore

java.lang.Object
cloud.opencode.base.feature.store.LruFeatureStore
All Implemented Interfaces:
FeatureStore

public class LruFeatureStore extends Object implements FeatureStore
LRU Feature Store LRU功能存储

In-memory store with LRU eviction policy.

带有LRU淘汰策略的内存存储。

Features | 主要功能:

  • LRU eviction - LRU淘汰
  • Capacity limit - 容量限制
  • Thread-safe - 线程安全

Usage Examples | 使用示例:

// Store with max 100 features
FeatureStore store = new LruFeatureStore(100);

// When capacity exceeded, least recently used features are evicted
for (int i = 0; i < 150; i++) {
    store.save(Feature.builder("feature-" + i).build());
}
// Only 100 most recent features remain
Since:
JDK 25, opencode-base-feature V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • LruFeatureStore

      public LruFeatureStore(int maxSize)
      Create LRU store with max size 创建具有最大大小的LRU存储
      Parameters:
      maxSize - the maximum number of features | 最大功能数
  • Method Details

    • save

      public void save(Feature feature)
      Description copied from interface: FeatureStore
      Save a feature 保存功能
      Specified by:
      save in interface FeatureStore
      Parameters:
      feature - the feature to save | 要保存的功能
    • find

      public Optional<Feature> find(String key)
      Description copied from interface: FeatureStore
      Find a feature by key 根据键查找功能
      Specified by:
      find in interface FeatureStore
      Parameters:
      key - the feature key | 功能键
      Returns:
      optional containing feature if found | 如果找到则包含功能的Optional
    • findAll

      public List<Feature> findAll()
      Description copied from interface: FeatureStore
      Find all features 查找所有功能
      Specified by:
      findAll in interface FeatureStore
      Returns:
      list of all features | 所有功能的列表
    • delete

      public boolean delete(String key)
      Description copied from interface: FeatureStore
      Delete a feature 删除功能
      Specified by:
      delete in interface FeatureStore
      Parameters:
      key - the feature key | 功能键
      Returns:
      true if deleted | 如果删除成功返回true
    • exists

      public boolean exists(String key)
      Description copied from interface: FeatureStore
      Check if a feature exists 检查功能是否存在
      Specified by:
      exists in interface FeatureStore
      Parameters:
      key - the feature key | 功能键
      Returns:
      true if exists | 如果存在返回true
    • count

      public int count()
      Description copied from interface: FeatureStore
      Get the count of features 获取功能数量
      Specified by:
      count in interface FeatureStore
      Returns:
      feature count | 功能数量
    • clear

      public void clear()
      Description copied from interface: FeatureStore
      Clear all features 清除所有功能
      Specified by:
      clear in interface FeatureStore
    • getMaxSize

      public int getMaxSize()
      Get the maximum size 获取最大大小
      Returns:
      max size | 最大大小