CacheManager

Struct CacheManager 

Source
pub struct CacheManager { /* private fields */ }
Expand description

缓存管理器

全局单例或通过依赖注入管理,负责:

  • Redis 连接管理
  • Key 索引维护
  • 插件缓存清理

Implementations§

Source§

impl CacheManager

Source

pub async fn new( redis_url: &str, config: CacheConfig, ) -> Result<Self, CacheError>

创建新的 CacheManager

§Arguments
  • redis_url - Redis 连接 URL
  • config - 缓存配置
§Returns
  • Result<Self, CacheError> - CacheManager 实例或错误
Source

pub async fn new_with_defaults(redis_url: &str) -> Result<Self, CacheError>

使用默认配置创建 CacheManager

§Arguments
  • redis_url - Redis 连接 URL
§Returns
  • Result<Self, CacheError> - CacheManager 实例或错误
Source

pub fn create_plugin_cache(&self, plugin_id: String) -> PluginCache

为插件创建 Cache 实例

§Arguments
  • plugin_id - 插件 ID
§Returns
  • PluginCache - 插件缓存实例
Source

pub async fn clear_plugin(&self, plugin_id: &str) -> Result<u64, CacheError>

清理指定插件的所有缓存

§Arguments
  • plugin_id - 插件 ID
§Returns
  • Result<u64, CacheError> - 删除的 Key 数量
§性能优化
  • 优先使用索引获取 Key(快速)
  • 仅在索引为空或需要完整性保证时使用 SCAN
Source

pub async fn clear_plugin_for_upgrade( &self, plugin_id: &str, ) -> Result<u64, CacheError>

清理插件缓存(用于升级场景)

§Arguments
  • plugin_id - 插件 ID
§Returns
  • Result<u64, CacheError> - 删除的 Key 数量
Source

pub async fn clear_plugin_for_disable( &self, plugin_id: &str, force: bool, ) -> Result<u64, CacheError>

清理插件缓存(用于禁用场景)

§Arguments
  • plugin_id - 插件 ID
  • force - 是否强制清理
§Returns
  • Result<u64, CacheError> - 删除的 Key 数量
Source

pub async fn clear_module( &self, plugin_id: &str, module: &str, ) -> Result<u64, CacheError>

清理指定插件的指定模块缓存

§Arguments
  • plugin_id - 插件 ID
  • module - 模块标识(biz),如 userorderconfig
§Returns
  • Result<u64, CacheError> - 删除的 Key 数量
§Example
// 清空 user_plugin 插件的 user 模块缓存
cache_manager.clear_module("user_plugin", "user").await?;

// 清空 order_service 插件的 order 模块缓存
cache_manager.clear_module("order_service", "order").await?;
Source

pub async fn health_check(&self) -> Result<(), CacheError>

Redis 连接健康检查

§Returns
  • Result<(), CacheError> - 健康检查结果
§用途

用于定期检查 Redis 连接是否正常,可用于自动重连机制

Trait Implementations§

Source§

impl Clone for CacheManager

Source§

fn clone(&self) -> CacheManager

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more