当前位置:网站首页>[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 !
边栏推荐
- Blue decides red - burst CS teamserver password
- Thinkadmin V6 arbitrary file read vulnerability (cve-2020-25540)
- FRP reverse proxy +msf get shell
- Briefly talk about other uses of operation and maintenance monitoring
- Implement the foreach method of array
- 多进程编程(三):消息队列
- 布隆过滤器
- NC50965 Largest Rectangle in a Histogram
- Seckill system design
- What are the recommended thesis translation software?
猜你喜欢

有哪些比较推荐的论文翻译软件?

Attributeerror: 'tuple' object has no attribute 'layer' problem solving

Shell脚本基本使用

Introduction and use of ftrace tool

DotNet圈里一个优秀的ORM——FreeSql

pod生命周期详解

mm中的GAN模型架构
![[shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a](/img/f2/f3b8899aa774dd32006c5928d370f1.gif)
[shutter] Introduction to the official example of shutter Gallery (learning example | email application | retail application | wealth management application | travel application | news application | a

Mutual exclusion and synchronization of threads

Two common methods and steps of character device registration
随机推荐
Introduction and use of ftrace tool
Logback configuration file
maya渔屋建模
Bypass AV with golang
腾讯云免费SSL证书扩展文件含义
Mutual exclusion and synchronization of threads
Array common operation methods sorting (including ES6) and detailed use
antv x6节点拖拽到画布上后的回调事件(踩大坑记录)
Feature Engineering: summary of common feature transformation methods
Luogu_ P2010 [noip2016 popularization group] reply date_ Half enumeration
Graduation summary
One of the reasons why setinterval timer does not take effect in ie: the callback is the arrow function
Pageoffice - bug modification journey
Form form instantiation
Architecture: load balancing
微信小程序获取某个元素的信息(高、宽等),并将px转换为rpx。
[shutter] image component (image component introduction | image constructor | image.network constructor | image.asset constructor)
关于QByteArray存储十六进制 与十六进制互转
FRP reverse proxy +msf get shell
Blue decides red - burst CS teamserver password