欢迎去看原著,转载来自于:
引用
http://www.iteye.com/topic/1125445
先说Ehcache吧,比较常用,配置简单,性能也可以
Hibernate缺省的缓存框架,下载的话网上一搜一大把,首先的话需要导入Ehcache所需jar包,然后配置配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
updateCheck="false">
<diskStore path="java.io.tmpdir" />
<!-- 用户账号缓存 -->
<cache name="accountCache" eternal="false" maxElementsInMemory="1000"
overflowToDisk="false" diskPersistent="false" timeToIdleSeconds="0"
timeToLiveSeconds="300" memoryStoreEvictionPolicy="LRU">
</cache>
</ehcache>
使用Ehcache:
/* 声明缓存管理容器 */
CacheManager cm = new CacheManager("info-cache.xml");
/* 获取缓存实例 */
Cache cache = cm.getCache("accountCache");
cache.put(new Element("account", "zhangsan"));
System.out.println(cache.get("account").getValue());
从上述示例中我们可以看出,Ehcache的基本使用比较简单,接下来,我们再次演示另外一种缓存框架,SapphireCache。SapphireCache是一种新缓存框架,感觉配置和使用上更为简单和方便,避免了很多不必要的层次封装,降低资源开销的同时,还提升了很强的缓存吞吐性与分布式缓存的并发性。
导入配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sapphire PUBLIC
"-//Sapphire Cache//DTD Sapphire Configuration 1.1//CN"
"http://sapphire-cache.googlecode.com/files/sapphire-cache-1.1.9.dtd">
<sapphire>
<!-- 缓存注解服务驱动 -->
<service:annotation-driven auto="true" />
<!-- 缓存持久化全局配置 -->
<diskStore path="java.io.tmpdir" diskEternal="false"
timeToRemoveSeconds="60" />
<!-- 缺省缓存配置 -->
<cache eternal="false" maxElementsInSize="100" maxCacheInMemory="1"
capacityUnit="kByte" overflowToDisk="true" diskPersistent="false"
timeToLiveSeconds="60" cacheCleanupPolicy="FIFO">
</cache>
</sapphire>
使用示例:
/* 初始化缓存管理容器 */
CacheManager cacheManager = new SapphireCacheManager();
/* 获取缓存实例 */
Cache cache = cacheManager.getCache("defaultCache");
cache.put("account", "admin");
System.out.println(cache.get("account"));
分享到:
相关推荐
cache、ehcache等缓存使用,实现存对象读对象等等
Mybatis-ehcache 1.2.1源码(ehcache-cache-mybatis-ehcache-1.2.1.tar.gz)
Mybatis-ehcache 1.2.1源码(ehcache-cache-mybatis-ehcache-1.2.1.zip)
ehcache3-samples, 关于使用 Ehcache 3,一些示例/教程 Ehcache示例这里知识库包含有关 Ehcache 3用法的示例和教程。示例'basic'演示 Ehcache 3的基本配置和用法'集群'- 演示如何在Terracotta服务器上使用分布式缓存...
Ehcache使用: CacheManager主要的缓存管理类,一般一个应用为一个实例,如下 CacheManager.create();也可以使用new CacheManager的方式创建 默认的配置文件为ehcache.xml文件,也可以使用不同的配置: ...
NULL 博文链接:https://cczakai.iteye.com/blog/1622708
Spring与ehcache结合使用,本地缓存的实现
shiro-demo使用ehcache做缓存.zip
有基于ehcache 自己的cache实现,也有是自己实现的,基于ehcache的写磁盘的缓存设置,已经测试过,可以放心使用。
EhCache使用详解,HIBERNATE缓冲
ehcache配置使用详解,里面有具体的例子
1.解压缩到目录下,复制ehcache-monitor-kit-1.0.0\lib\ehcache-probe-1.0.0.jar包到application的web-inf/lib目录下 2.将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名...
该压缩包用于缓存服务部署,jboss集成ehcache,解压启动即可访问,实现缓存共用
介绍 ehcache的导入过程。使用CacheManager 创建并管理Cache,默认的配置文件为ehcache.xml文件,也可以使用不同的配置。
在Spring+Hibernate集成环境中使用EhCache缓存做的开发测试,在线程中打开数据库查询数据,及关闭数据库后查询数据的结果.
Ehcache API,页面缓存,分布式缓存。
ehcache使用例子,maven项目。
NULL 博文链接:https://cuisuqiang.iteye.com/blog/2050675
hibernate+ehcache hibernate+ehcache hibernate+ehcache hibernate+ehcache hibernate+ehcache
ehcache的依赖包,使用ehcache缓存机制必备