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. C# 事务提交(非数据库)

    .Net 2.0开始支持 static void Main(string[] args) { using (TransactionScope ts = new TransactionScope()) ...

  2. 惠普台式机在UEFI BIOS设置通电自动开机 影响电脑自动重启关不了机设置

    设置通电自动开机 影响电脑自动重启关不了机设置   惠普台式机在UEFI BIOS中 1. 开机时不断点击F10键进入BIOS,选择Advanced(高级)然后选择Boot Options,点击回车 ...

  3. linux下FTP服务搭建(1)

    1.FTP介绍: FTP (File Transfer Protocol,文件传输协议)主要用来文件传输,尤其适用于大文件传输,提供上传下载功能 FTP官方网站:https://filezilla-p ...

  4. 几种IO情况的学习和总结 关于 =====阻塞/非阻塞以及同步/异步区别

    同步IO和异步IO,阻塞IO和非阻塞IO分别是什么,到底有什么区别?不同的人在不同的上下文下给出的答案是不同的.所以先限定一下本文的上下文. 背景是Linux环境下的network IO. 在进行解释 ...

  5. 牛客网练习赛28A

    题目链接:https://www.nowcoder.com/acm/contest/200/A 链接:https://www.nowcoder.com/acm/contest/200/A来源:牛客网 ...

  6. [转]jQuery: get table column/row index remove table column (by column number)

    本文转自:http://www.xinotes.org/notes/note/1087/ <!DOCTYPE html><html><head> <title ...

  7. Murano py27和py34的兼容处理

    tox.ini envlist = py27,py34,pep8 1. django.utils.encoding.force_unicode替换成django.utils.encoding.forc ...

  8. Linux禁ping

    A.临时允许PING操作的命令为:# >/proc/sys/net/ipv4/icmp_echo_ignore_all B.永久允许PING配置方法. /etc/sysctl.conf 中增加一 ...

  9. 一个position为fixed的div,宽高自适应,怎样让它水平垂直都在窗口居中?

    .div{ position: fixed; left: %; top: %; -webkit-transform: translate(-%, -%); transform: translate(- ...

  10. 上传文件,使用FormData进行Ajax请求,jsoncallback跨域

    通过传统的form表单提交的方式上传文件: <form id= "uploadForm" action= "http://localhost:8080/cfJAX_ ...