最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot ehcache 配置使用方法代碼詳解

 更新時間:2021年06月26日 08:30:31   作者:m17193095294  
EhCache是一個比較成熟的Java緩存框架,Springboot對ehcache的使用非常支持,所以在Springboot中只需做些配置就可使用,且使用方式也簡易,今天給大家分享springboot ehcache 配置使用教程,一起看看吧

EhCache是一個比較成熟的Java緩存框架,最早從hibernate發(fā)展而來, 是進程中的緩存系統(tǒng),它提供了用內(nèi)存,磁盤文件存儲,以及分布式存儲方式等多種靈活的cache管理方案,快速簡單。

Springboot對ehcache的使用非常支持,所以在Springboot中只需做些配置就可使用,且使用方式也簡易。

下面通過本文給大家介紹springboot ehcache 配置使用方法,具體內(nèi)容如下所示:

1. pom 引入依賴

    <!-- Ehcache -->
		<dependency>
			<groupId>net.sf.ehcache</groupId>
			<artifactId>ehcache</artifactId>
		</dependency>

2.resources 目錄下直接放個文件ehcache.xml

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

    <diskStore path="java.io.tmpdir"/>

  <!--defaultCache:echcache的默認緩存策略  -->
    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            maxElementsOnDisk="10000000"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU">
        <persistence strategy="localTempSwap"/>
    </defaultCache>
        
    <!-- 菜單緩存策略 -->
    <cache name="menucache"
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            maxElementsOnDisk="10000000"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU">
        <persistence strategy="localTempSwap"/>
    </cache>
    
</ehcache>

3.在Service層 方法上加上注解

@CacheEvict(value="menucache", allEntries=true) ,更新緩存

@Cacheable(key="'menu-'+#parentId",value="menucache") 讀取緩存,"'menu-'+#parentId" 通配符,也可以直接寫死字符串

menucache 對應(yīng) 上面 xmlname="menucache"

/**刪除菜單
	 * @param MENU_ID
	 * @www.fhadmin.org
	 */
	@CacheEvict(value="menucache", allEntries=true)
	public void deleteMenuById(String MENU_ID) throws Exception{
		this.cleanRedis();
		menuMapper.deleteMenuById(MENU_ID);
	}

	/**
	 * 通過ID獲取其子一級菜單
	 * @param parentId
	 * @return
	 * @www.fhadmin.org
	 */
	@Cacheable(key="'menu-'+#parentId",value="menucache")
	public List<Menu> listSubMenuByParentId(String parentId) throws Exception {
		return menuMapper.listSubMenuByParentId(parentId);
	}

到此這篇關(guān)于springboot ehcache 配置使用方法代碼詳解的文章就介紹到這了,更多相關(guān)springboot ehcache 配置使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

巴彦县| 南木林县| 娄底市| 额敏县| 凤凰县| 龙游县| 涿州市| 仙桃市| 渭南市| 北辰区| 临沂市| 乡城县| 托里县| 交城县| 大连市| 苍南县| 临桂县| 简阳市| 绵竹市| 墨江| 交口县| 霍林郭勒市| 弋阳县| 固始县| 延津县| 孟津县| 鲁山县| 明光市| 云霄县| 峡江县| 济源市| 永新县| 巴林左旗| 静海县| 措勤县| 哈密市| 玉溪市| 余庆县| 普陀区| 寻甸| 邵阳县|