Class InMemoryFeatureStore

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

public class InMemoryFeatureStore extends Object implements FeatureStore
In-Memory Feature Store 内存功能存储

Thread-safe in-memory implementation of FeatureStore.

FeatureStore的线程安全内存实现。

Features | 主要功能:

  • Thread-safe operations - 线程安全操作
  • Fast lookups - 快速查找
  • No persistence - 无持久化

Usage Examples | 使用示例:

FeatureStore store = new InMemoryFeatureStore();
store.save(Feature.builder("feature-1").alwaysOn().build());
store.save(Feature.builder("feature-2").percentage(50).build());

boolean exists = store.exists("feature-1"); // true
int count = store.count(); // 2
Since:
JDK 25, opencode-base-feature V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • InMemoryFeatureStore

      public InMemoryFeatureStore()
      Create in-memory store 创建内存存储
  • 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