当前位置:网站首页>[jetcache] jetcache configuration description and annotation attribute description
[jetcache] jetcache configuration description and annotation attribute description
2022-07-03 00:36:00 【No8g siege lion】
Contents of this article
One 、 Configuration instructions
Two 、 Annotation property description
One 、 Configuration instructions
yml Profile case ( If not used springboot, Direct configuration GlobalCacheConfig It's similar , Refer to the quick start tutorial ):
jetcache:
statIntervalMinutes: 15
areaInCacheName: false
hidePackages: com.alibaba
local:
default:
type: caffeine
limit: 100
keyConvertor: fastjson
expireAfterWriteInMillis: 100000
otherArea:
type: linkedhashmap
limit: 100
keyConvertor: none
expireAfterWriteInMillis: 100000
remote:
default:
type: redis
keyConvertor: fastjson
valueEncoder: java
valueDecoder: java
poolConfig:
minIdle: 5
maxIdle: 20
maxTotal: 50
host: ${redis.host}
port: ${redis.port}
otherArea:
type: redis
keyConvertor: fastjson
valueEncoder: kryo
valueDecoder: kryo
poolConfig:
minIdle: 5
maxIdle: 20
maxTotal: 50
host: ${redis.host}
port: ${redis.port}
The general description of the configuration is as follows :
attribute | The default value is | explain |
---|---|---|
jetcache.statIntervalMinutes | 0 | Statistical interval ,0 Indicates no statistics |
jetcache.areaInCacheName | true | jetcache-anno hold cacheName As a remote cache key Prefix ,2.4.3 Previous versions always put areaName Add to cacheName in , therefore areaName It also appears in key In the prefix .2.4.4 It can be configured later , In order to stay remote key The compatible default is true, But for new projects false More reasonable . |
jetcache.hiddenPackages | nothing | @Cached and @CreateCache Automatic generation name When , In order not to let name Too long ,hiddenPackages The specified package name prefix is truncated |
jetcache.[local|remote].${area}.type | nothing | Cache type .tair、redis For the currently supported remote cache ;linkedhashmap、caffeine Is the currently supported local cache type |
jetcache.[local|remote].${area}.keyConvertor | nothing | key Global configuration of the converter , At present, there is only one implemented keyConvertor:fastjson . Only when using @CreateCache And the cache type is LOCAL Can be specified as none , At this point through equals Methods to identify key. Method cache must specify keyConvertor |
jetcache.[local|remote].${area}.valueEncoder | java | Global configuration of serializer . only remote Type of cache needs to be specified , Optional java and kryo |
jetcache.[local|remote].${area}.valueDecoder | java | Global configuration of serializer . only remote Type of cache needs to be specified , Optional java and kryo |
jetcache.[local|remote].${area}.limit | 100 | Global configuration of the largest element per cache instance , only local Type of cache needs to be specified . Note the limitations of each cache instance , Not all of them , For example, here we specify 100, And then use @CreateCache Created two cache instances ( And the annotation is not set localLimit attribute ), Then the limit of each cache instance is 100 |
jetcache.[local|remote].${area}.expireAfterWriteInMillis | infinity | Global configuration that specifies the timeout in milliseconds ( Used to be defaultExpireInMillis) |
jetcache.local.${area}.expireAfterAccessInMillis | 0 | need jetcache2.2 above , In Milliseconds , Specify how long you haven't visited , Just invalidate the cache , Currently, only local cache supports .0 Indicates that this function is not used . |
The above table ${area} Corresponding @Cached and @CreateCache Of area attribute . Note that if the annotation does not specify area, The default value is "default".
About cache timeout , There are multiple places to specify , To clarify :
- put And so on , Then this time shall prevail
- put The timeout method is not specified , Use Cache The default timeout of the instance
- Cache The default timeout of the instance , By means of @CreateCache and @Cached Upper expire Attribute specifies , If not specified , Use yml Global configuration defined in , for example @Cached(cacheType=local) Use jetcache.local.default.expireAfterWriteInMillis, If not specified, it is infinite
Two 、 Annotation property description
JetCache Method cache and SpringCache similar , It provides TTL Support , To ensure final agreement , And support L2 cache .JetCache2.4 Support annotation based cache update and deletion in the future .
stay spring In the environment , Use @Cached Annotations can add caching to a method ,@CacheUpdate For updating the cache ,@CacheInvalidate Used to remove cache elements . Annotations can be added to interfaces or classes , The annotated class must be a spring bean, for example :
public interface UserService {
@Cached(name="userCache.", key="#userId", expire = 3600)
User getUserById(long userId);
@CacheUpdate(name="userCache.", key="#user.userId", value="#user")
void updateUser(User user);
@CacheInvalidate(name="userCache.", key="#userId")
void deleteUser(long userId);
}
key Use Spring Of SpEL Script to specify . If you want to use parameter names ( Like here key="#userId"
), Project compilation settings target It has to be for 1.8 Format , And specify javac Of -parameters Parameters , Otherwise, use key="args[0]"
This is in the form of subscript access .
@CacheUpdate and @CacheInvalidate Of name and area Property must be the same as @Cached identical ,name Attributes can also be used as cache Of key Prefix .
@Cached Notes and @CreateCache The properties of are very similar , But a few more :
attribute | The default value is | explain |
---|---|---|
area | “default” | If multiple caches are configured in the configuration area, Specify which... To use here area |
name | Undefined | Specifies the unique name of the cache , It's not necessary , If not specified , Can use class name + Method name .name Will be used for remote caching key Prefix . In addition, in Statistics , A short and meaningful name will improve readability . |
key | Undefined | Use SpEL Appoint key, If not specified, it will be automatically generated according to all parameters . |
expire | Undefined | Timeout time . If there is no definition in the annotation , Will use global configuration , If the global configuration is not defined at this time , It's infinity |
timeUnit | TimeUnit.SECONDS | Appoint expire The unit of |
cacheType | CacheType.REMOTE | The type of cache , Include CacheType.REMOTE、CacheType.LOCAL、CacheType.BOTH. If defined as BOTH, Will use LOCAL and REMOTE Combined into two-level cache |
localLimit | Undefined | If cacheType by LOCAL or BOTH, This parameter specifies the maximum number of elements in the local cache , To control memory usage . If there is no definition in the annotation , Will use global configuration , If the global configuration is not defined at this time , Then for 100 |
localExpire | Undefined | Only when the cacheType by BOTH When applicable , In memory Cache Specify a different timeout , Usually it should be less than expire |
serialPolicy | Undefined | Specifies how the remote cache is serialized . Optional value is SerialPolicy.JAVA and SerialPolicy.KRYO. If there is no definition in the annotation , Will use global configuration , If the global configuration is not defined at this time , Then for SerialPolicy.JAVA |
keyConvertor | Undefined | Appoint KEY The transformation of , Used to convert complex KEY Type is converted to a type acceptable to the cache implementation , The current support KeyConvertor.FASTJSON and KeyConvertor.NONE.NONE It means no conversion ,FASTJSON Complex objects can be KEY convert to String. If there is no definition in the annotation , Will use global configuration . |
enabled | true | Whether to activate cache . For example, a dao Add cache annotation to the method , Because there can be no cache in some call scenarios , So you can set enabled by false, Normal calls do not use the cache , Can be used where needed CacheContext.enableCache Activate the cache in the callback , Cache active tags in ThreadLocal On , After this flag is set , all enable=false All caches are activated |
cacheNullValue | false | When the return value of the method is null Whether to cache when |
condition | Undefined | Use SpEL Specified conditions , If the expression returns true Only go to the cache to query |
postCondition | Undefined | Use SpEL Specified conditions , If the expression returns true Only update the cache when , The evaluation is carried out after the implementation of the method , So you can access #result |
@CacheInvalidate Note that :
attribute | The default value is | explain |
---|---|---|
area | “default” | If multiple caches are configured in the configuration area, Specify which... To use here area, Pointing to corresponding @Cached Definition . |
name | Undefined | Specifies the unique name of the cache , Pointing to corresponding @Cached Definition . |
key | Undefined | Use SpEL Appoint key |
condition | Undefined | Use SpEL Specified conditions , If the expression returns true To delete , Accessible method results #result |
@CacheUpdate Note that :
attribute | The default value is | explain |
---|---|---|
area | “default” | If multiple caches are configured in the configuration area, Specify which... To use here area, Pointing to corresponding @Cached Definition . |
name | Undefined | Specifies the unique name of the cache , Pointing to corresponding @Cached Definition . |
key | Undefined | Use SpEL Appoint key |
value | Undefined | Use SpEL Appoint value |
condition | Undefined | Use SpEL Specified conditions , If the expression returns true To perform the update , Accessible method results #result |
Use @CacheUpdate and @CacheInvalidate When , Related cache operations may fail ( Such as network IO error ), Therefore, it is very important to specify the timeout of the cache .
@CacheRefresh Note that :
attribute | The default value is | explain |
---|---|---|
refresh | Undefined | Refresh interval |
timeUnit | TimeUnit.SECONDS | Time unit |
stopRefreshAfterLastAccess | Undefined | Specify the key How long does it take to stop refreshing without access , If not specified, it will always refresh |
refreshLockTimeout | 60 second | The type is BOTH/REMOTE Cache refresh for , At the same time, only one server will be refreshing , This server will place a distributed lock in the remote cache , This configuration specifies the timeout of the lock |
@CachePenetrationProtect annotation :
When cache access misses , Protect concurrent loading behavior . The current version implements a single JVM The protection inside , Is the same JVM The same one key There is only one thread to load , Other threads wait for results .
For parameters with no default values defined above , If not specified , Will use yml Global configuration specified in , For global configuration, please refer to Configuration instructions .
The end !
边栏推荐
- NC20806 区区区间间间
- University of Toronto:Anthony Coache | 深度强化学习的条件可诱导动态风险度量
- Basic use of shell script
- Linux软件:如何安装Redis服务
- 简单聊聊运维监控的其他用途
- Where can I find the English literature of the thesis (except HowNet)?
- Bigder:32/100 测试发现的bug开发认为不是bug怎么处理
- Don't want teachers to see themselves with cameras in online classes? Virtual camera you deserve!
- 【JetCache】JetCache的配置说明和注解属性说明
- 【雅思阅读】王希伟阅读P2(阅读填空)
猜你喜欢
MySQL 23道经典面试吊打面试官
多进程编程(一):基本概念
Two common methods and steps of character device registration
Basic use of shell script
University of Toronto:Anthony Coache | 深度强化学习的条件可诱导动态风险度量
使用jenkins之二Job
奥斯陆大学:Li Meng | 基于Swin-Transformer的深度强化学习
Install docker and use docker to install MySQL
setInterval定时器在ie不生效原因之一:回调的是箭头函数
【单片机项目实训】八路抢答器
随机推荐
Briefly talk about other uses of operation and maintenance monitoring
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
ftrace工具的介绍及使用
有哪些比较推荐的论文翻译软件?
Cmake basic use
Multiprocess programming (I): basic concepts
Should you study kubernetes?
How SQLSEVER removes data with duplicate IDS
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
Maya fishing house modeling
经济学外文文献在哪查?
An excellent orm in dotnet circle -- FreeSQL
University of Toronto:Anthony Coache | 深度强化学习的条件可诱导动态风险度量
What website can you find English literature on?
CMake基本使用
Kubernetes simple introduction to writing YML
setInterval定时器在ie不生效原因之一:回调的是箭头函数
form表单实例化
【Pulsar文档】概念和架构/Concepts and Architecture
UART、RS232、RS485、I2C和SPI的介绍