Skip to content

缓存(forge-starter-cache)

工程位置:forge-server/forge-framework/forge-starter-parent/forge-starter-cache。Maven artifactIdforge-starter-cachesrc/main/java 里有 35 个 Java 文件。

引入

xml
<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.RedissonConfig
  • com.mdframe.forge.starter.cache.managed.config.ManagedCacheAutoConfiguration

配置属性

forge.cachecom.mdframe.forge.starter.cache.managed.properties.ManagedCacheProperties

字段类型类内默认值说明
annotationEnabledbooleantrue是否启用注解拦截。关闭后业务方法全部穿透。
applicationCodeString无默认值应用编码,默认取 spring.application.name
namespaceString"forge:managed-cache"Redis 控制面和数据对象前缀。
policyRefreshSecondslong30Pub/Sub 丢失时重新校准策略快照的最小间隔。

类内默认值不是官方启动配置。各服务 application.yml 可以覆盖。

注解

@ForgeCacheConfig

com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheConfig

类注释:声明一个命名缓存的代码默认策略和不可变安全边界。成员本身没有 javadoc,下表按成员名和默认值列出。

成员类型默认值说明
nameString必填,无默认缓存名。
descriptionString""策略说明。
modeCacheModeCacheMode.REDIS默认模式。
allowedModesCacheMode[]{LOCAL, REDIS, MULTI}允许切换的模式边界。
scopeCacheScopeCacheScope.TENANT作用域。
localTtlSecondslong60本地缓存 TTL(秒)。
redisTtlSecondslong1800Redis TTL(秒)。
localMaxSizeint1000本地缓存最大条目。
cacheNullbooleanfalse是否缓存空值。
nullTtlSecondslong30空值 TTL(秒)。

@ForgeCachePut

com.mdframe.forge.starter.cache.managed.annotation.ForgeCachePut

源码无成员注释。标在方法上。

成员类型默认值说明
cacheNameString必填,无默认写入的缓存名。
keyString""缓存键,可为空。

@ForgeCacheable

com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheable

源码无成员注释。标在方法上。

成员类型默认值说明
cacheNameString必填,无默认读取的缓存名。
keyString""缓存键,可为空。

@ForgeCacheEvict

com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheEvict

源码无成员注释。标在方法上。

成员类型默认值说明
cacheNameString必填,无默认失效的缓存名。
keyString""要删的键。allEntries=true 时可空。
allEntriesbooleanfalse是否清空整个缓存名。

@ForgeCacheConfigs

com.mdframe.forge.starter.cache.managed.annotation.ForgeCacheConfigs

@ForgeCacheConfig 的容器注解。

成员类型默认值说明
valueForgeCacheConfig[]必填,无默认一组 @ForgeCacheConfig

源码类型清单

下面只列 forge-starter-cache 自己的公开类型。

接口

  • com.mdframe.forge.starter.cache.managed.context.CacheIdentityProvider
  • com.mdframe.forge.starter.cache.managed.store.ManagedCacheHandle
  • com.mdframe.forge.starter.cache.service.ICacheService

枚举

  • CacheControlAction
  • CacheMode
  • CacheScope

  • CacheDefinitionRegistrar
  • CacheDefinitionResolver
  • CacheTransactionExecutor
  • ForgeCacheAspect
  • ForgeCacheKeyResolver
  • ForgeManagedCacheManager
  • LocalCacheHandle
  • ManagedCacheAutoConfiguration
  • ManagedCacheCodecs
  • ManagedCacheProperties
  • MultiLevelCacheHandle
  • RedisCacheHandle
  • RedissonCacheServiceImpl
  • RedissonConfig
  • SessionCacheIdentityProvider

相关文档