项目使用Redis
一、导入JAR包
<dependency>
<groupId>com.uns.inf</groupId>
<artifactId>unsc</artifactId>
<version>0.0.1</version>
</dependency>
二、配置spring-unsc.xml配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:unscache="http://www.uns.com/schema/uns-cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.uns.com/schema/uns-cache http://www.uns.com/schema/uns-cache/uns-cache-1.0.0.xsd">
<unscache:config appName="rule_engine">
<unscache:redis connection-cache-size="2"
connection-max-size="20" timeout="5000"
servers="172.22.203.171:7001,172.22.203.171:7002" />
</unscache:config>
</beans>
三、属性讲解
Config参数说明:
appName 应用名称必输
serialization 序列化方式(默认json)可选
ttl 缓存时间(默认1800秒)可选
origin 缓存位置(默认远程、分本地和远程)可选
switch 缓存开关(默认true,false时缓存不起作用)可选
redis参数说明:
整项可选(不配置时缓存本地)
connection-cache-size redis空闲连接数
connection-max-size redis最大连接数
timeout redis超时时间
servers redis集群地址(格式是服务地址+端口,多个地址用逗号隔开)
四、注解使用
方法上指定@UnsCache
全部参数如下,只有特殊情况下再配置相应的参数
@UnsCache(key="",action=Action.CLEAN,origin=OriginType.LOCAL,prefix="",scope=Scope.Local,seriatype=SeriaType.DEFAULT,ttl=1213)
参数说明:
Key 指定缓存key(默认系统自己计算)可选
Prefix 指定key的前缀可选
Action 操作类型(默认是NONE,clean是清除缓存,refresh是刷新缓存)可选
Origin 选择缓存的位置(默认远程、分本地和远程)可选
Scope 缓存的范围(是本应用使用还是所有应用使用)可选
Seriatype序列化方式(默认json)可选
Ttl 指定缓存时间(默认1800秒)可选
五、静态使用(静态类)
本地
UnsLocalCache
redis远程
UnsRedisCache
UnsRedisCache.removeValue(key);
UnsRedisCache.hincrByFloat(key, "RULE_ENGINCE", value.doubleValue());
六、JAR包下载(见附件)
七、使用实例