CacheRegistry class

缓存注册表

提供统一的缓存管理入口,所有 CacheStrategy 实例可自动或手动注册到此处。 支持批量初始化、清理过期数据、清空所有缓存等操作。

使用示例:

// 1. 创建缓存时自动注册
final userCache = CacheStrategy<UserEntity>(
  mode: CacheMode.hybrid,
  cacheKey: 'user_cache',
  autoRegister: true,  // 自动注册到 CacheRegistry
  ...
);

// 2. 或手动注册
CacheRegistry.register('user_cache', userCache);

// 3. App 启动时统一初始化和清理
await CacheRegistry.initAll();
await CacheRegistry.cleanExpiredAll();

// 4. 查看已注册的缓存
print(CacheRegistry.registeredKeys);

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

registeredCount int
获取已注册的缓存数量
no setter
registeredKeys Iterable<String>
获取已注册的缓存 key 列表
no setter

Static Methods

cleanExpiredAll() Future<void>
清理所有已注册缓存的过期数据
clearAll() Future<void>
清空所有已注册的缓存
clearRegistry() → void
清空注册表(不清空缓存数据,仅移除注册)
get<T>(String key) CacheStrategy<T>?
获取指定缓存(带类型安全检查)
initAll() Future<void>
初始化所有已注册的缓存
printStats() → void
打印缓存统计信息
register(String key, CacheStrategy cache) → void
注册缓存
unregister(String key) → void
注销缓存