缓存(forge-starter-cache)
工程位置:forge-server/forge-framework/forge-starter-parent/forge-starter-cache。Maven artifactId 是 forge-starter-cache。src/main/java 里有 35 个 Java 文件。
引入
<dependency>
<groupId>com.mdframe.forge</groupId>
<artifactId>forge-starter-cache</artifactId>
</dependency>自动装配
META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports 登记了:
com.mdframe.forge.starter.cache.config.RedissonConfigcom.mdframe.forge.starter.cache.managed.config.ManagedCacheAutoConfiguration
配置属性
forge.cache(com.mdframe.forge.starter.cache.managed.properties.ManagedCacheProperties)
| 字段 | 类型 | 类内默认值 | 说明 |
|---|---|---|---|
annotationEnabled | boolean | true | 是否启用注解拦截。关闭后业务方法全部穿透。 |
applicationCode | String | 无默认值 | 应用编码,默认取 spring.application.name。 |
namespace | String | "forge:managed-cache" | Redis 控制面和数据对象前缀。 |
policyRefreshSeconds | long | 30 | Pub/Sub 丢失时重新校准策略快照的最小间隔。 |
类内默认值不是官方启动配置。各服务 application.yml 可以覆盖。
注解
@ForgeCacheConfig
com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheConfig
类注释:声明一个命名缓存的代码默认策略和不可变安全边界。成员本身没有 javadoc,下表按成员名和默认值列出。
| 成员 | 类型 | 默认值 | 说明 |
|---|---|---|---|
name | String | 必填,无默认 | 缓存名。 |
description | String | "" | 策略说明。 |
mode | CacheMode | CacheMode.REDIS | 默认模式。 |
allowedModes | CacheMode[] | {LOCAL, REDIS, MULTI} | 允许切换的模式边界。 |
scope | CacheScope | CacheScope.TENANT | 作用域。 |
localTtlSeconds | long | 60 | 本地缓存 TTL(秒)。 |
redisTtlSeconds | long | 1800 | Redis TTL(秒)。 |
localMaxSize | int | 1000 | 本地缓存最大条目。 |
cacheNull | boolean | false | 是否缓存空值。 |
nullTtlSeconds | long | 30 | 空值 TTL(秒)。 |
@ForgeCachePut
com.mdframe.forge.starter.cache.managed.annotation.ForgeCachePut
源码无成员注释。标在方法上。
| 成员 | 类型 | 默认值 | 说明 |
|---|---|---|---|
cacheName | String | 必填,无默认 | 写入的缓存名。 |
key | String | "" | 缓存键,可为空。 |
@ForgeCacheable
com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheable
源码无成员注释。标在方法上。
| 成员 | 类型 | 默认值 | 说明 |
|---|---|---|---|
cacheName | String | 必填,无默认 | 读取的缓存名。 |
key | String | "" | 缓存键,可为空。 |
@ForgeCacheEvict
com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheEvict
源码无成员注释。标在方法上。
| 成员 | 类型 | 默认值 | 说明 |
|---|---|---|---|
cacheName | String | 必填,无默认 | 失效的缓存名。 |
key | String | "" | 要删的键。allEntries=true 时可空。 |
allEntries | boolean | false | 是否清空整个缓存名。 |
@ForgeCacheConfigs
com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheConfigs
@ForgeCacheConfig 的容器注解。
| 成员 | 类型 | 默认值 | 说明 |
|---|---|---|---|
value | ForgeCacheConfig[] | 必填,无默认 | 一组 @ForgeCacheConfig。 |
源码类型清单
下面只列 forge-starter-cache 自己的公开类型。
接口
com.mdframe.forge.starter.cache.managed.context.CacheIdentityProvidercom.mdframe.forge.starter.cache.managed.store.ManagedCacheHandlecom.mdframe.forge.starter.cache.service.ICacheService
枚举
CacheControlActionCacheModeCacheScope
类
CacheDefinitionRegistrarCacheDefinitionResolverCacheTransactionExecutorForgeCacheAspectForgeCacheKeyResolverForgeManagedCacheManagerLocalCacheHandleManagedCacheAutoConfigurationManagedCacheCodecsManagedCachePropertiesMultiLevelCacheHandleRedisCacheHandleRedissonCacheServiceImplRedissonConfigSessionCacheIdentityProvider
