Asgard 缓存模块 skill。Use when configuring or using Asgard caching, including CacheConfig, memory cache, Redis cache, multi-level cache behavior, cache access through AbsAsgardContext, cache keys, expiration, and cache-related graceful degradation.
用于配置和使用 Asgard 多级缓存系统。Asgard 支持内存缓存(一级)+ Redis 分布式缓存(二级)的多级缓存策略,获取时先查内存缓存,未命中再查 Redis;写入时同时写入二级缓存。
app.yaml 中配置缓存开关和选项AbsAsgardContext.Cache 访问缓存服务| 配置项 | 说明 | 必填 |
|---|---|---|
caching.enabled | 是否启用整个缓存模块 | 是 |
caching.memory.enabled | 是否启用内存缓存(一级) | 至少启用一种 |
caching.memory.defaultExpirationMinutes | 内存缓存默认过期分钟数 | 是(启用时) |
caching.memory.sizeLimit |
| 内存缓存大小限制(字节) |
| 否 |
caching.memory.compactOnMemoryPressure | 内存压力压缩阈值 (0-1) | 否,默认 0.9 |
caching.redis.enabled | 是否启用 Redis 缓存(二级) | 至少启用一种 |
caching.redis.connectionString | Redis 连接字符串 | 是(启用时) |
caching.redis.instanceName | Redis 实例名称前缀 | 否 |
caching.redis.defaultExpirationMinutes | Redis 默认过期分钟数 | 是(启用时) |
caching.redis.database | Redis 数据库编号 (0-15) | 否 |
多级缓存策略:
| 方法 | 说明 |
|---|---|
GetAsync<T>(key) | 获取缓存数据 |
SetAsync<T>(key, value, expiration) | 设置缓存数据 |
RemoveAsync(key) | 移除缓存数据 |
ExistsAsync(key) | 检查缓存是否存在 |