shiro使用ehcache缓存权限数据

1.引入依赖

<!-- https://mvnrepository.com/artifact/net.sf.ehcache/ehcache -->
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.10.4</version>
        </dependency>

2.引入ehcache的配置文件,文件名任意

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">

    <!--临时目录-->
    <diskStore path="java.io.tmpdir"/>

    <!--缓存设置-->
    <!--
        maxElementsInMemory:内存最大对象数量
        eternal:是否永久有效
        timeToIdleSeconds:最大空闲时间
        timeToLiveSeconds:最大生存时间
        overflowToDisk:溢出到磁盘
        maxElementsOnDisk:磁盘最大对象数量
        diskPersistent:对象是否持久化
        diskExpiryThreadIntervalSeconds:对象清理的线程最大的轮循时间
        memoryStoreEvictionPolicy:淘汰策略
        LRU:最近一段时间最少使用的被清理
    -->
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
</ehcache>

3.在spring的配置文件中注册shiro的缓存管理器,并将第二步的配置文件路径指定给缓存管理器

<!--注册缓存管理器-->
<bean id="ehCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
	<property name="cacheManagerConfigFile" value="classpath:/spring/applicationContext-ehcache.xml"></property>
</bean>

4.将缓存管理器注给安全管理器

<!--安全管理器-->
	<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
		<property name="realm" ref="bosRealm"></property>
		<property name="cacheManager" ref="ehCacheManager"></property>
	</bean>

shiro已经整和了 ehcache缓存,到此为止完成了缓存配置,缓存数据和从缓存中取数据由shiro自己完成。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值