您的位置:首页 > 大数据

二级缓存处理大数据 用ehcache.xml配置文件

2014-06-09 19:31 489 查看

二级缓存大量数据的解决方案

数据很大

二级缓存 存储大数据,让 内存和磁盘文件进行交互,数据库中的不变的数据在磁盘上,这样就可以少和数据库进行交互了

ehcache.xml 放在src下

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
<!--存储位置-->
<diskStore path="C:\\TEMP1"/>
<defaultCache
maxElementsInMemory="12"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="false"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>

<Cache
name="cn.itcast.hiberate.sh.domain.Classes"        <!--针对的类对象,它最好都是不变的 只执行查询语句-->
maxElementsInMemory="5"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>


磁盘和内存进行交互,加快速度

@Test
public void testAllClasses(){
Session session = sessionFactory.openSession();
List<Classes> classesList = session.createQuery("from Classes").list();
session.close();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


在c://Temp1中会多个文件,查询数据库的数据会放在此文件中,以减少和数据库的交互
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: