Git 项目推荐 | 基于 J2Cache 的多级缓存框架

时间:2022-05-06
本文章向大家介绍Git 项目推荐 | 基于 J2Cache 的多级缓存框架,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

基于j2cache的理念,重新设计开发的一套分布式缓存。支持2级并不限于2级的多级缓存系统。

github地址:atoms

配置文件:

<?xml version="1.0" encoding="UTF-8"?><atoms>
    <broadcast type="redis" >
        <broadcastConfig host="192.168.1.53" port="6379"/>
    </broadcast>
    <serializer type="fst"/>
    <cache level="1" type="ehcache" delete_atom="true" ><!-- expiredOperator="update" waitTime="100" --><!-- expiredOperator: update,delete  当为update时waitTime有效-->
        <cacheConfig configFile="ehcache.xml"/>
    </cache>
    <cache level="2" type="redis">
        <cacheConfig host="192.168.1.53" port="6379" timeout="2000" database="13" namespace="atoms" maxTotal="-1" maxIdle="2000"
         maxWaitMillis="100" minEvictableIdleTimeMillis="864000000" minIdle="1000" numTestsPerEvictionRun="10" lifo="false"
         softMinEvictableIdleTimeMillis="10" testOnBorrow="true" testOnReturn="false" testWhileIdle="false" timeBetweenEvictionRunsMillis="300000"
         blockWhenExhausted="true" password=""/>
    </cache>
    <cache level="3" type="redis">
        <cacheConfig host="192.168.1.22" port="6379" timeout="2000" database="13" namespace="atoms" maxTotal="-1" maxIdle="2000"
         maxWaitMillis="100" minEvictableIdleTimeMillis="864000000" minIdle="1000" numTestsPerEvictionRun="10" lifo="false"
         softMinEvictableIdleTimeMillis="10" testOnBorrow="true" testOnReturn="false" testWhileIdle="false" timeBetweenEvictionRunsMillis="300000"
         blockWhenExhausted="true" password=""/>
    </cache></atoms>

使用代码:

CacheChannel cc=CacheChannel.getInstance();cc.set("jobell", "hello", "nihaoya");cc.evict("jobell", "hello");while(true){
    Object value=cc.get("jobell", "hello");
    if(value==null){
        System.out.println("==============="+value);
    }else{
        System.out.println("==============="+value);
    }}