Pyramid缓存组件
Pyramid是基于AOP实现的缓存组件,可使用本地缓存和Redis缓存。 本文档对应的版本号为 0.0.5
- 导入
增加maven依赖,reimport
<dependency>
<groupId>com
.meeruu
</groupId
>
<artifactId>pyramid
</artifactId
>
<version>0.0.5</version
>
</dependency
>
- @Pyramid
以方法入参参数数组列表中指定的一项为Key,以返回值为Value,存入缓存。若Key为List,Value为List<Model>,则需要在Model中用@PyramidKey来指定对象中Key元素。目前仅支持一对一,多对多,还不支持一对多的情况(比如String—>List<String>)。
参数列表
参数名释义默认值
cacheName缓存空间名称“”key缓存标识“”collection是否为集合falsecollectionArgsIndex方法入参参数数组下标0onlyLocal只使用本地缓存falseonlyDistributed只使用分布式缓存falseredisExpirationredis缓存失效时间-1023L(单位秒,-1为永久有效,[0,-])nativeExpiration本地缓存失效时间600(单位秒,[0,-])refreshTime缓存刷新时间-1(单位秒,-1为不用刷新,[0,-])
Model
@Data
@NoArgsConstructor
@AllArgsConstructor
public class User {
String key
;
String name
;
@PyramidKey
public String
getKey(){
return this.key
;
}
}
Single
@Pyramid(key
= "#key",cacheName
= "cachetest",collectionArgsIndex
= 1,redisExpiration
= 30,nativeExpiration
= 30)
public User
fresh(Integer id
,String key
){
return new User(key
,key
+"name");
}
@Pyramid(key
= "#user.key",cacheName
= "cachetest",redisExpiration
= 30,nativeExpiration
= 30)
public User
fresh(User user
){
return user
;
}
List
User
@Pyramid(key
= "#users?.![key]",cacheName
= "cachetest",collection
= true,redisExpiration
= 30,nativeExpiration
= 30)
public List
<User> fresh(List
<User> users
){
return users
;
}
- 删除缓存@Del
参数名释义默认值
cacheName缓存空间名称“”key缓存标识“”collection是否为集合false
Single
@Del(key
= "#user.key",cacheName
= "cachetest")
public User
delete(User user
){
return user
;
}
List
@Del(key
= "#users?.![key]",cacheName
= "cachetest",collection
= true)
public List
<User> delete(List
<User> users
){
return users
;
}