secra-memory 0.1.1

A unified memory cache management library for plugin systems, built on top of moka
Documentation
/// 内存模块
///
/// 使用 moka 提供统一的内存缓存管理功能
///
/// ## 功能特性
///
/// - **统一治理**:所有缓存操作必须通过 MemoryManager,插件不能直接访问 moka
/// - **强隔离**:每个插件拥有独立的命名空间,避免 Key 冲突
/// - **生命周期管理**:插件卸载/升级时自动清理相关缓存
/// - **极简 API**:插件侧 API 简单易用,隐藏 moka 细节
/// - **与 Cache 模块一致**:实现相同的 `Cache` trait,支持无缝切换
///
/// ## Key 格式规范
///
/// 所有内存缓存 Key 必须遵循以下格式:
/// ```text
/// {system}:plugin:{plugin_id}:{biz}:{key}
/// ```
///
/// 示例:
/// - `secra:plugin:user_plugin:user:123`
/// - `secra:plugin:order_service:order:2024:001`
///
/// ## 使用示例
///
/// ### 基座系统
///
/// ```rust
/// // 1. 创建 MemoryManager
/// let memory_manager = MemoryManager::new_with_defaults();
///
/// // 2. 为插件创建 Cache 实例
/// let plugin_cache = memory_manager.create_plugin_cache("user_plugin".to_string());
/// ```
///
/// ### 插件代码
///
/// ```rust
/// // 1. 设置缓存
/// #[derive(Serialize, Deserialize)]
/// struct User { id: u64, name: String }
///
/// let user = User { id: 123, name: "Alice".to_string() };
/// cache.set("user:123", &user, None).await?;
///
/// // 2. 获取缓存
/// let user: Option<User> = cache.get("user:123").await?;
///
/// // 3. 删除缓存
/// cache.delete("user:123").await?;
///
/// // 4. 清理所有缓存
/// cache.clear().await?;
///
/// // 5. 按模块清理缓存
/// cache.clear_module("user").await?; // 清理 user 模块的所有缓存
/// ```
mod cache;
mod config;
mod error;
mod manager;
mod plugin;

// 公开导出
pub use cache::Cache;
pub use config::MemoryConfig;
pub use error::CacheError;
pub use error::CacheError as MemoryError; // 为了兼容性,也导出为 MemoryError
pub use manager::MemoryManager;
pub use plugin::PluginMemoryCache;