Ehcache是JAVA内制的一个缓存框架!

目的:缓解频繁读取数据库的压力;

初步配置如下:

 <?xml version="1.0" encoding="UTF-8"?>
<ehcache updateCheck="false" name="shirocache">
<diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
maxElementsOnDisk="0"
eternal="true"
overflowToDisk="true"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
diskSpoolBufferSizeMB="50"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LFU"
/>
<cache name="shiro_cache"
maxElementsInMemory="2000"
maxEntriesLocalHeap="2000"
eternal="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
maxElementsOnDisk="0"
overflowToDisk="true"
memoryStoreEvictionPolicy="FIFO"
statistics="true">
</cache>
</ehcache>

使用如下:

1、存储数据;

                    CacheManager cacheManager = CacheManager.create(url);
Cache cache=cacheManager.getCache("shiro_cache");
Element element = new Element("pwd", password);
cache.put(element);

2、读取数据

             URL url = getClass().getResource("/ehcache/ehcache.xml");
CacheManager cacheManager = CacheManager.create(url);
Cache cache=cacheManager.getCache("shiro_cache");
Element element = cache.get("pwd");
System.out.println(element.toString());

Ehcache的配置与使用的更多相关文章

  1. (转)springMVC+mybatis+ehcache详细配置

    一. Mybatis+Ehcache配置 为了提高MyBatis的性能,有时候我们需要加入缓存支持,目前用的比较多的缓存莫过于ehcache缓存了,ehcache性能强大,而且位各种应用都提供了解决方 ...

  2. ehcache.xml配置参数

    <ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLoc ...

  3. hibernate二级缓存ehcache hibernate配置详解

    <!-----------------hibernate二级缓存ehcache------------------------->hibernate配置 <prop key=&quo ...

  4. spring中ehcache的配置和使用方法

    继续上篇,这篇介绍服务层缓存,ehcache一般的配置和用法 一.添加jar包引用 修改pom.xml文件,加入: <dependency> <groupId>org.spri ...

  5. SpringBoot中整合Redis、Ehcache使用配置切换 并且整合到Shiro中

    在SpringBoot中Shiro缓存使用Redis.Ehcache实现的两种方式实例 SpringBoot 中配置redis作为session 缓存器. 让shiro引用 本文是建立在你是使用这sh ...

  6. EhCache的配置

    JPA和Hibernate的二级缓存都是这样做的 代码目录: 这是基础的jar包,如果少的话,再去maven下载 <!-- Spring --> <dependency> &l ...

  7. Ehcache缓存配置

    Cache的配置很灵活,官方提供的Cache配置方式有好几种.你可以通过声明配置.在xml中配置.在程序里配置或者调用构造方法时传入不同的参数. 你可以将Cache的配置从代码中剥离出来,也可以在使用 ...

  8. Hibernate学习笔记之EHCache的配置

    Hibernate默认二级缓存是不启动的,启动二级缓存(以EHCache为例)需要以下步骤: 1.添加相关的包: Ehcache.jar和commons-logging.jar,如果hibernate ...

  9. ehcache 的配置

    配置:一.在src目录下加入ehcache.xml: <cache name="SimplePageCachingFilter" maxElementsInMemory=&q ...

  10. 02_MyBatis项目结构,所需jar包,ehcache.xml配置,log4j.properties,sqlMapConfig.xml配置,SqlMapGenerator.xml配置

     项目结构(所需jar包,配置文件) sqlMapConfig.xml的配置内容如下: <?xmlversion="1.0"encoding="UTF-8&qu ...

随机推荐

  1. Hibernate上传数据到数据库,从数据库读取数据到本地模板代码

    1.Hibernate上传数据到数据库: //创建一个session对象 Session session1=HibernateTools.getSession(); //Fenciresult数据库表 ...

  2. hdu3746 KMP-next数组的应用

    Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. 问题:git处理中文名称时候显示为编码形式(已解决)

    问题描述: Untracked files: (use "git add <file>..." to include in what will be committed ...

  4. sshd_config注释

    [root@H0f ~]# cat /etc/ssh/sshd_config #update by H0f -- # $OpenBSD: sshd_config,v // :: djm Exp $ # ...

  5. java——newInstance()方法和new关键字

    https://www.cnblogs.com/liuyanmin/p/5146557.html 这两个都可以创建一个对象,那么这样个东西有什么不一样呢?什么时候用new,什么时候用newInstan ...

  6. Window 远程连接 Ubuntu 系统

    安装XRDP 服务, 用windows远程连接ubuntu 1. Step 1 – Install xRDP sudo apt-get update sudo apt-get install xrdp ...

  7. Spring---数据缓存(未完待续)

    1.为什么需要数据缓存? 程序的瓶颈大都在数据库,而内存的速度是远远大于硬盘的,当我们需要重复读取相同数据时,一次又一次的请求数据库或者远程服务,导致大量的时间浪费在数据库或者 远程服务上,导致程序性 ...

  8. Spark各个组件的概念,Driver进程

    spark应用涉及的一些基本概念: 1.mater:主要是控制.管理和监督整个spark集群 2.client:客户端,将用应用程序提交,记录着要业务运行逻辑和master通讯. 3.sparkCon ...

  9. maya2012无法安装卸载激活失败

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  10. (转)shell脚本输出带颜色字体

    shell脚本输出带颜色字体 原文:http://blog.csdn.net/andylauren/article/details/60873400 输出特效格式控制:\033[0m  关闭所有属性  ...