Skip to content

baileyfu/xcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

缓存框架V1.0.3

对缓冲层的抽象,简化缓存使用;可接入本地缓存和第三方缓存
未指定localCache和remoteCache或者需缓存返回对象的方法的参数为空,则不做任何操作
CacheManager为主要操作类,单例实现,可单独使用,如:
CacheManager cm=CacheManager.getInstance();
cm.putToRemote(key,value);
cm.removeRemote(shardName,key);

###版本变更记录

版本 日期 描述
V1.0.0 2017-06-06 完成预期功能,可投入使用
V1.0.1 2017-08-01 支持分片
V1.0.2 2017-11-06 包结构重置;LOGGER分离
V1.0.3 2018-04-25 新增自定义Schema

e.g

Spring配置增加:

...
xmlns:xcache="http://www.xteam.org/xcache"
xsi:schemaLocation="http://www.xteam.org/xcache http://www.xteam.org/xcache/xcache-1.0.xsd"
...
<bean id="localCache" class="xcache.bean.SingleMapCache"/>
<bean id="remoteCache" class="xcache.redis.SingleRedisCache">
		<constructor-arg>
			<!-- 需配置org.springframework.data.redis.core.RedisTemplate -->
			<ref bean="redisTemplate"/>
		</constructor-arg>
</bean>
<xcache:config local="localCache" remote="remoteCache"/>
<xcache:autoproxy/>

使用:

@XCache(key="#user.id",remove="globalUpdate",expiring=5,timeUnit=TimeUnit.HOUR,prefix="CLASS_SCOPE_PREFIX",suffix="CLASS_SCOPE_SUFFIX")
public class XService{
	@RCache
	public String getBankCard(String userId){
	...
	}
	@RCache(key="#user.id")
	public String getBankCard(User user){
	...
	}
	@RCache(key="#userInfo[0]")
	public String getBankCard(String[] userInfo){
	...
	}
	@RCache(shardName="6",key="#userInfo['id'] + '-' + #userInfo['name']")
	public String getBankCard(Map userInfo){
	...
	}
	@LCache(key="myConfig",remove={"updateConfig","deleteConfig"},throwable=true,expiring=10,timeUnit=TimeUnit.MINUTE,prefix="PREFIX",suffix="SUFFIX")
	public Map MyConfig(){
	...
	}
}

已接入的本地缓存:

xcache.bean.SingleMapCache 单Map实现,不自动清理,线程安全
xcache.bean.SingleMapAutoCleanCache 单Map实现,可自动清理过期内容,线程安全
xcache.bean.MultiMapCache 双Map实现,不自动清理,线程安全
xcache.bean.MultiMapAutoCleanCache 双Map实现,可自动清理过期内容,线程安全
xcache.bean.LRUCache 单LURMap实现,不自动清理,线程安全
xcache.bean.MultiLRUCache 双LURMap实现,不自动清理,线程安全
xcache.bean.EHCache 基于Ehcache实现的Cache

已接入的第三方缓存

xcache.redis.SingleRedisCache 基于Spring的RedisTemplate实现
xcache.redis.SingleRedisShardCache 基于Spring的RedisTemplate实现;可指定数据库ID
xcache.redis.RedisClusterCache(未实现) 基于Redis集群实现

配置详解

@RCache:启用第三方缓存
@LCache:启用本地缓存
@XCache:配置Class全局默认参数;无throwable选项
*所有的参数都不是必填项

参数名 类型 默认值 描述
key String 缓存主键生成方式,三种方式:
1.不指定;以方法的第一个参数dump成字符串作为key
2.SpEL;表达式引用参数名称正确则解析,否则将表达式以字符串形式作为key;若多个参数名称相同,则取第一个参数参与表达式运算
3.字符串形式,直接作为key
shardName String 数据库分库名;目前仅Redis使用,用于指定数据库下标
remove String数组 触发缓存清理的方法名;匹配所有重载的方法
throwable Boolean false 是否抛出缓存操作时的异常
expiring Integer 0 有效期
timeUnit xcache.em.TimeUnit MINUTE 有效期单位
prefix String key前缀
suffix String key后缀

Releases

No releases published

Packages

No packages published

Languages