使用ehcache缓存数据

ehcache缓存权限数据


pom.xml坐标
<!-- 缓存 -->
<dependency>
    <groupId>net.sf.ehcache</groupId>
    <artifactId>ehcache-core</artifactId>
    <version>2.6.11</version>
</dependency>
ehcache配置文件
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">
    <!--磁盘存储的路径 临时文件目录-->
    <diskStore path="java.io.tmpdir"/>
    <!-- maxElementsInMemory内存中最大允许创建的对象数-->
    <!-- eternal内存中对象是否为永久的,如果是,超时设置将被忽略,对象从不过期 -->
    <!--timeToIdleSeconds设置对象在它过期之前的空闲时间  可选属性,默认值是0,也就是可闲置时间无穷大-->
    <!--timeToLiveSeconds设置对象在失效前允许存活时间。最大时间介于创建时间和失效时间之间。仅当对象不是永久有效时使用,默认是0.,也就是element存活时间无穷大-->
    <!--overflowToDisk配置此属性,当内存中对象数量达到maxElementsInMemory时,Ehcache将会对象写到磁盘中。-->
    <!--maxElementsOnDisk磁盘中最大缓存对象数,若是0表示无穷大-->
    <!--diskPersistent是否缓存虚拟机重启期数据。-->
    <!--diskExpiryThreadIntervalSeconds磁盘失效线程运行时间间隔,默认是120秒-->
    <!--memoryStoreEvictionPolicy当达到maxElementsInMemory限制时,Ehcache将会根据指定的策略去清理内存。默认策略是LRU(最近最少使用)。你可以设置为FIFO(先进先出)或是LFU(较少使用)-->
    <!--overflowToDisk  -->
    <defaultCache maxElementsInMemory="10000"  
                eternal="false"                         
                  timeToIdleSeconds="120"           
                timeToLiveSeconds="120"         
                overflowToDisk="true"               
                maxElementsOnDisk="10000000"
                diskPersistent="false"          
                diskExpiryThreadIntervalSeconds="120" 
                memoryStoreEvictionPolicy="LRU" />
</ehcache>

在spring中配置ehcache
<!-- 注册安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="bosRealm"></property>
    <property name="cacheManager" ref="ehCacheManager"></property>
</bean>
<!-- 注册缓存管理器 -->
<bean id="ehCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
    <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"></property>
</bean>
注意:实体类需要序列化
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值