1.缓存专业名字
缓存击穿:缓存中没有,数据库中有
缓存穿透:数据在缓存中没有,数据中也没有
缓存的雪崩:缓存有一个存活时间,某一时刻,大量的缓存都过期了,大量的击穿缓存的数据,会造成数据库的瘫痪
命中率=命中个数/总个数
第一次访问,访问中没有命中0 总数1
第二次访问,缓存命中1,总是2
hit越高,缓存提升的性能就越好
2.集成EhCache
1.在spring-shiro.xml文件中配置缓存管理器并引用缓存管理器
<!--安全管理器-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!--注册自定义数据源-->
<property name="realm" ref="crmRealm"/>
<!--注册缓存管理器-->
<property name="cacheManager" ref="cacheManager"/>
</bean>
<!-- 缓存管理器 -->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<!-- 设置配置文件 -->
<property name="cacheManagerConfigFile" value="classpath:shiro-ehcache.xml"/>
</bean>
3.添加缓存配置文件
<ehcache>
<defaultCache
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
memoryStoreEvictionPolicy="LRU">
</defaultCache>
</ehcache>