shiro articles] four. shiro cache configuration

Articles] [shiro III. Shiro login authentication and authorization on a case
[shiro articles] III. Login authentication and authorization under shiro Case

Lengthy article directories can be viewed through the right side of Contents

shiro cache configuration

Project Preparation

  1. New Project day64-shiro-03-cache
  2. The day64-shiro-02-spring to move over to direct, detailed reference to the above two
  3. It can also be directly day64-shiro-02-spring configuration cache
    Here Insert Picture Description

1 cache configuration

1.1 Adding cached profiles ehcache.xml

<ehcache>
    <diskStore path="java.io.tmpdir/shiro-ehcache"/>
    <cache name="authorizationCache"
           maxEntriesLocalHeap="2000"
           eternal="false"
           timeToIdleSeconds="3600"
           timeToLiveSeconds="0"
           overflowToDisk="false"
           statistics="true">
    </cache>
    <cache name="authenticationCache"
           maxEntriesLocalHeap="2000"
           eternal="false"
           timeToIdleSeconds="3600"
           timeToLiveSeconds="0"
           overflowToDisk="false"
           statistics="true">
    </cache>
</ehcache>

1.2 spring configuration cache container

<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
   <!-- cache配置文件 -->
    <property name="cacheManagerConfigFile" value="classpath:ehcache.xml" />
</bean>

Here Insert Picture Description

1.3 spring container security configuration data source attributes

<!-- 启用缓存,默认false; -->
<property name="cachingEnabled" value="true" />
<!--启用身份验证缓存,即缓存AuthenticationInfo信息,默认false -->
<property name="authenticationCachingEnabled" value="true" />
<!--缓存AuthenticationInfo信息的缓存名称 -->
<property name="authenticationCacheName" value="authenticationCache" />
<!--启用授权缓存,即缓存AuthorizationInfo信息,默认false -->
<property name="authorizationCachingEnabled" value="true" />
<!--缓存AuthorizationInfo信息的缓存名称 -->
<property name="authorizationCacheName" value="authorizationCache" />

Here Insert Picture Description

1.4 Test

Before did not configure the cache, output in a statement authorization will find that each call to add and delete methods will be the authorization method is called repeatedly. After setting the cache after the first call will be cached, the next time the call will not be called the authorization method. Similarly certification. . .

Published 56 original articles · won praise 11 · views 4078

Guess you like

Origin blog.csdn.net/TheNew_One/article/details/104120283