JetCache
https://blog.csdn.net/sinat_32366329/article/details/80260944
依賴(lài)
<dependency>
<groupId>com.alicp.jetcache</groupId>
<artifactId>jetcache-starter-redis-lettuce</artifactId>
<version>2.5.9</version>
</dependency>
配置
@Configuration
@EnableMethodCache(basePackages = "input your package name!!!")
@EnableCreateCacheAnnotation
public class CacheConfig {
}
jetcache:
statIntervalMinutes: 15
areaInCacheName: false
hiddenPackages: com.alibaba
local:
default:
type: caffeine
limit: 100
keyConvertor: fastjson
expireAfterWriteInMillis: 100000
remote:
default:
type: redis.lettuce
keyConvertor: fastjson
valueEncoder: kryo
valueDecoder: kryo
uri: redis://XXX@host:6379/6
使用
public interface UserService {
@Cached(name="userCache.", key="#userId", expire = 3600 ,cacheType = CacheType.BOTH)
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);
}