Framework
ApiHug SDK Spring Cache 扩展
包含 spring-cache 简单封装:
HopeCacheErrorHandler
RedissonClient
自动配置 hope.redis.enable=true
@EnableCaffeineCaching
@EnableRedisCaching
@EnableEhcacheCaching
支持hope.cache
配置路径, 配置对象: HopeCacheProperties
配置 | 备注 |
---|---|
caffeine | Caffeine配置 |
caffeine.allowInFlightCacheCreation | 是否允许创建非定义cache |
caffeine.timeToLive | 默认TTL |
caffeine.caches | 多cache配置map,参考CaffeineSpec |
caffeine.caches[*].initialCapacity | 参考 CaffeinSpec |
caffeine.caches[*].maximumWeight | 参考 CaffeinSpec |
caffeine.caches[*].maximumSize | 参考 CaffeinSpec |
caffeine.caches[*].recordStats | 参考 CaffeinSpec |
caffeine.caches[*].keyStrength | 参考 CaffeinSpec |
caffeine.caches[*].valueStrength | 参考 CaffeinSpec |
caffeine.caches[*].expireAfterWrite | 参考 CaffeinSpec |
caffeine.caches[*].expireAfterAccess | 参考 CaffeinSpec |
caffeine.caches[*].refreshAfterWrite | 参考 CaffeinSpec |
redis | Redis 配置 |
redis.allowInFlightCacheCreation | 是否允许创建非预定义cache |
redis.timeToLive | 默认TTL |
redis.caches | 多cache配置map |
redis.caches[*].timeToLive | 单个cache TTL |
redis.caches[*].cacheNullValues | 单个cache 运行NULL值 |
redis.caches[*].keyPrefix | 单个cache keyPrefix |
redis.caches[*].useKeyPrefix | 单个cache useKeyPrefix |
redis.caches[*].enableStatistics | 单个cache 打开统计 |
redis.caches[*].enableTransactions | 单个cache 事务管理 |
redis.caches[*].serializer | 单个cache 序列化 |
ehCache | EhCache配置 |
ehCache.heap | Heap 实体数量(个) |
ehCache.offHeap | OffHeap 大小(存储) |
ehCache.disk | Disk大小(存储) |
ehCache.duration | 默认TTL |
ehCache.caches | 各个EhCache配置 |
ehCache.caches[*].keyClz | key 类型 |
ehCache.caches[*].valueClz | value 类型 |
ehCache.caches[*].heap | Heap 实体数量(个) |
ehCache.caches[*].offHeap | OffHeap 大小(存储) |
ehCache.caches[*].disk | Disk大小(存储) |
ehCache.caches[*].duration | TTL |
errorPolicy | 错误处理策略 |
errorPolicy.swallowGetException | 忽略Get错误 |
errorPolicy.swallowPutException | 忽略Put错误 |
errorPolicy.swallowEvictException | 忽略Evict错误 |
errorPolicy.swallowClearException | 忽略Clear错误 |
errorPolicy.logStackTraces | 打印错误堆栈 |
timeToLive | 默认TTL(兜底) |
配置路径:hope.redis
; 配置对象: HopeRedisProperties
众和了spring 本身的配置:
Hope 更借鉴 spring.data.redis 配置方式和 Spring Data RedisProperties 比较类似;
配置 | 备注 |
---|---|
cluster | 集群节点配置 |
cluster.max-redirects. | Maximum number of redirects to follow when executing commands across the cluster. |
cluster.nodes | List of “host:port” pairs to bootstrap from. This represents an “initial” list of cluster nodes and is required to have at least one entry. |
sentinel | sentinel节点 |
sentinel.master | sentinel Master 节点 |
sentinel.nodes | List of “host:port” pairs. |
sentinel.username | Login username for authenticating with sentinel(s). |
sentinel.password | Password for authenticating with sentinel(s). |
master | master、slaves配置方式 |
master.master | master 节点 host:port |
master.slaves | slave 节点 host:port 列表 |
master.username | 用户名 |
master.password | 密码 |
database | Database index used by the connection factory. |
enable | - |
config | 通过路径引入 redission 配置文件 |
url | Connection URL. Overrides host, port, username, and password. Example: redis://user:password@example.com:6379 |
host | Redis server host. |
username | Login username of the redis server. |
password | Login password of the redis server. |
port | Redis server port. |
ssl | Whether to enable SSL support. |
poolSize | 连接池大小 |
idleSize | 最小空闲连接数 |
idleTimeout | 连接空闲超时,单位:毫秒 |
connectionTimeout | 连接超时,单位:毫秒 |
timeout | 命令等待超时,单位:毫秒 |
clientName | Client name to be set on connections with CLIENT SETNAME . |
根据 errorPolicy
配置进行处理, 如需抛出组装成 CacheErrorsEnum
输出:
错误码 | 错误标题 | 错误描述 | 错误描述2 |
---|---|---|---|
1002000001 | FAIL_GET_CACHE | fail get data from the cache | 缓存没有命中 |
1002000002 | FAIL_EVICT_CACHE | fail evict data from the cache | 清除缓存失败 |
1002000003 | FAIL_PUT_CACHE | fail put data to the cache | 更新缓存失败 |
1002000004 | FAIL_CLEAR_CACHE | fail clear cache | 清理缓存失败 |
1002000005 | FAIL_CREATE_CACHE | fail create cache | 创建缓存错误 |
1002000006 | CACHE_CONFIGURATION_ILLEGAL | cache configuration illegal | 缓存配置错误 |
老的控制方式,根据 hope.cache.type 类型触发配置上下文,现已不支持!
@EnableCaffeineCaching
@EnableRedisCaching
@EnableEhcacheCaching