国产成人精品18p,天天干成人网,无码专区狠狠躁天天躁,美女脱精光隐私扒开免费观看

Java緩存ehcache的使用步驟

發(fā)布時(shí)間:2021-07-06 11:13 來(lái)源:腳本之家 閱讀:0 作者:彩虹咖啡 欄目: 開(kāi)發(fā)技術(shù)

目錄

一、pom.xml

<dependency>
		    <groupId>net.sf.ehcache</groupId>
		    <artifactId>ehcache</artifactId>
		    <version>2.10.4</version>
</dependency>

二、編寫(xiě)ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
 
	<cacheManagerPeerProviderFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
		properties="peerDiscovery=automatic, multicastGroupAddress=198.1.1.1,
         multicastGroupPort=10001,
         timeToLive=1" />
 
	<cacheManagerPeerListenerFactory
		class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
		properties="port=10001,socketTimeoutMillis=60000" />
 
	<!-- 磁盤(pán)緩存位置 -->
	<diskStore path="java.io.tmpdir/anywhere" />
 
	
	<cache name="oneCache" maxElementsInMemory="1500" eternal="false"
		timeToIdleSeconds="900" timeToLiveSeconds="900" overflowToDisk="false"
		memoryStoreEvictionPolicy="LRU">
		<cacheEventListenerFactory
			class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" properties="replicateRemovals=false"/>
		<bootstrapCacheLoaderFactory
			class="net.sf.ehcache.distribution.RMIBootstrapCacheLoaderFactory" />
	</cache>
	
</ehcache>

三、參數簡(jiǎn)介

四、Ehcache的緩存數據淘汰策略

FIFO:先進(jìn)先出

LFU:最少被使用,緩存的元素有一個(gè)hit屬性,hit值最小的將會(huì )被清出緩存。

LRU:最近最少使用,緩存的元素有一個(gè)時(shí)間戳,當緩存容量滿(mǎn)了,而又需要騰出地方來(lái)緩存新的元素的時(shí)候,那么現有緩存元素中時(shí)間戳離當前時(shí)間最遠的元素將被清出緩存

五、編寫(xiě)spring-ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
  <description>ehcache</description>
  <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
    <property name="cacheManager" ref="ehcache"/>
  </bean>
  <bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
    <property name="configLocation" value="classpath:/ehcache.xml"/>
  </bean>
</beans>

六、與Spring整合,導入到spring配置文件

<import resource="classpath:/spring-ehcache.xml"/>

七、Java Source code

使用類(lèi)導入:
    @Resource
    private org.springframework.cache.ehcacheEhCacheCacheManager cacheManager;

從獲取cache
    Cache cache = cacheManager.getCache(“oneCache”);
存入cache
    cache.put(“key”, “value”);
從cache中獲取
    ValueWrapper val = cache.get(“key”);
    String tempVal = (String)val.get();

到此這篇關(guān)于Java緩存ehcache的使用步驟的文章就介紹到這了,更多相關(guān)ehcache緩存的使用內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。

被按摩师玩弄到潮喷| 在线播放免费人成视频在线观看| 在线视频免费观看完整版高清| 欧美午夜刺激影院| 国产精品成人无码久久久久久| 国产精品三级国产电影|