Java進程內(nèi)緩存框架EhCache詳解
一:目錄
EhCache 簡介
Hello World 示例
Spring 整合
二: 簡介
2.1、基本介紹
EhCache 是一個純Java的進程內(nèi)緩存框架,具有快速、精干等特點,是Hibernate中默認(rèn)CacheProvider。Ehcache是一種廣泛使用的開源Java分布式緩存。主要面向通用緩存,Java EE和輕量級容器。它具有內(nèi)存和磁盤存儲,緩存加載器,緩存擴展,緩存異常處理程序,一個gzip緩存servlet過濾器,支持REST和SOAP api等特點。
Spring 提供了對緩存功能的抽象:即允許綁定不同的緩存解決方案(如Ehcache),但本身不直接提供緩存功能的實現(xiàn)。它支持注解方式使用緩存,非常方便。
2.2、主要的特性
- 快速
- 簡單
- 多種緩存策略
- 緩存數(shù)據(jù)有兩級:內(nèi)存和磁盤,因此無需擔(dān)心容量問題
- 緩存數(shù)據(jù)會在虛擬機重啟的過程中寫入磁盤
- 可以通過RMI、可插入API等方式進行分布式緩存
- 具有緩存和緩存管理器的偵聽接口
- 支持多緩存管理器實例,以及一個實例的多個緩存區(qū)域
- 提供Hibernate的緩存實現(xiàn)
2.3、 集成
可以單獨使用,一般在第三方庫中被用到的比較多(如mybatis、shiro等)ehcache 對分布式支持不夠好,多個節(jié)點不能同步,通常和redis一塊使用
2.4、 ehcache 和 redis 比較
ehcache直接在jvm虛擬機中緩存,速度快,效率高;但是緩存共享麻煩,集群分布式應(yīng)用不方便。
redis是通過socket訪問到緩存服務(wù),效率比Ehcache低,比數(shù)據(jù)庫要快很多,處理集群和分布式緩存方便,有成熟的方案。如果是單個應(yīng)用或者對緩存訪問要求很高的應(yīng)用,用ehcache。如果是大型系統(tǒng),存在緩存共享、分布式部署、緩存內(nèi)容很大的,建議用redis。
ehcache也有緩存共享方案,不過是通過RMI或者Jgroup多播方式進行廣播緩存通知更新,緩存共享復(fù)雜,維護不方便;簡單的共享可以,但是涉及到緩存恢復(fù),大數(shù)據(jù)緩存,則不合適。
三:事例
3.1、在pom.xml中引入依賴
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.2</version>
</dependency>
3.2、在src/main/resources/創(chuàng)建一個配置文件 ehcache.xml
默認(rèn)情況下Ehcache會自動加載classpath根目錄下名為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">
<!-- 磁盤緩存位置 -->
<diskStore path="java.io.tmpdir/ehcache"/>
<!-- 默認(rèn)緩存 -->
<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<!-- helloworld緩存 -->
<cache name="HelloWorldCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="5"
timeToLiveSeconds="5"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>
3.3、測試類
import entity.Dog;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class CacheTest {
public static void main(String[] args) {
// 1. 創(chuàng)建緩存管理器
CacheManager cacheManager = CacheManager.create("./src/main/resources/ehcache.xml");
// 2. 獲取緩存對象
Cache cache = cacheManager.getCache("HelloWorldCache");
// 3. 創(chuàng)建元素
Element element = new Element("key1", "value1");
// 4. 將元素添加到緩存
cache.put(element);
// 5. 獲取緩存
Element value = cache.get("key1");
System.out.println("value: " + value);
System.out.println(value.getObjectValue());
// 6. 刪除元素
cache.remove("key1");
Dog dog = new Dog("xiaohei", "black", 2);
Element element2 = new Element("dog", dog);
cache.put(element2);
Element value2 = cache.get("dog");
System.out.println("value2: " + value2);
Dog dog2 = (Dog) value2.getObjectValue();
System.out.println(dog2);
System.out.println(cache.getSize());
// 7. 刷新緩存
cache.flush();
// 8. 關(guān)閉緩存管理器
cacheManager.shutdown();
}
}
public class Dog {
private String name;
private String color;
private int age;
public Dog() {
}
public Dog(String name, String color, int age) {
super();
this.name = name;
this.color = color;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Dog [name=" + name + ", color=" + color + ", age=" + age + "]";
}
}
3.4、緩存配置
一:xml配置方式:
diskStore : ehcache支持內(nèi)存和磁盤兩種存儲 path :指定磁盤存儲的位置 defaultCache : 默認(rèn)的緩存 maxEntriesLocalHeap=“10000” eternal=“false” timeToIdleSeconds=“120” timeToLiveSeconds=“120” maxEntriesLocalDisk=“10000000” diskExpiryThreadIntervalSeconds=“120” memoryStoreEvictionPolicy=“LRU” cache :自定的緩存,當(dāng)自定的配置不滿足實際情況時可以通過自定義(可以包含多個cache節(jié)點) name : 緩存的名稱,可以通過指定名稱獲取指定的某個Cache對象 maxElementsInMemory :內(nèi)存中允許存儲的最大的元素個數(shù),0代表無限個 clearOnFlush:內(nèi)存數(shù)量最大時是否清除。 eternal :設(shè)置緩存中對象是否為永久的,如果是,超時設(shè)置將被忽略,對象從不過期。根據(jù)存儲數(shù)據(jù)的不同,例如一些靜態(tài)不變的數(shù)據(jù)如省市區(qū)等可以設(shè)置為永不過時 timeToIdleSeconds : 設(shè)置對象在失效前的允許閑置時間(單位:秒)。僅當(dāng)eternal=false對象不是永久有效時使用,可選屬性,默認(rèn)值是0,也就是可閑置時間無窮大。 timeToLiveSeconds :緩存數(shù)據(jù)的生存時間(TTL),也就是一個元素從構(gòu)建到消亡的最大時間間隔值,這只能在元素不是永久駐留時有效,如果該值是0就意味著元素可以停頓無窮長的時間。 overflowToDisk :內(nèi)存不足時,是否啟用磁盤緩存。 maxEntriesLocalDisk:當(dāng)內(nèi)存中對象數(shù)量達(dá)到maxElementsInMemory時,Ehcache將會對象寫到磁盤中。 maxElementsOnDisk:硬盤最大緩存?zhèn)€數(shù)。 diskSpoolBufferSizeMB:這個參數(shù)設(shè)置DiskStore(磁盤緩存)的緩存區(qū)大小。默認(rèn)是30MB。每個Cache都應(yīng)該有自己的一個緩沖區(qū)。 diskPersistent:是否在VM重啟時存儲硬盤的緩存數(shù)據(jù)。默認(rèn)值是false。 diskExpiryThreadIntervalSeconds:磁盤失效線程運行時間間隔,默認(rèn)是120秒。
二:編程方式配置
Cache cache = manager.getCache("mycache");
CacheConfiguration config = cache.getCacheConfiguration();
config.setTimeToIdleSeconds(60);
config.setTimeToLiveSeconds(120);
config.setmaxEntriesLocalHeap(10000);
config.setmaxEntriesLocalDisk(1000000);
3.5、Ehcache API
CacheManager:Cache的容器對象,并管理著(添加或刪除)Cache的生命周期。
// 可以自己創(chuàng)建一個Cache對象添加到CacheManager中 public void addCache(Cache cache); public synchronized void removeCache(String cacheName);
Cache: 一個Cache可以包含多個Element,并被CacheManager管理。它實現(xiàn)了對緩存的邏輯行為
Element:需要緩存的元素,它維護著一個鍵值對, 元素也可以設(shè)置有效期,0代表無限制
獲取CacheManager的方式:
可以通過create()或者newInstance()方法或重載方法來創(chuàng)建獲取CacheManager的方式:
public static CacheManager create(); public static CacheManager create(String configurationFileName); public static CacheManager create(InputStream inputStream); public static CacheManager create(URL configurationFileURL); public static CacheManager newInstance();
Ehcache的CacheManager構(gòu)造函數(shù)或工廠方法被調(diào)用時,會默認(rèn)加載classpath下名為ehcache.xml的配置文件。
如果加載失敗,會加載Ehcache jar包中的ehcache-failsafe.xml文件,這個文件中含有簡單的默認(rèn)配置?! ?/p>
// CacheManager.create() == CacheManager.create("./src/main/resources/ehcache.xml")
// 使用Ehcache默認(rèn)配置新建一個CacheManager實例
CacheManager cacheManager = CacheManager.create();
cacheManager = CacheManager.newInstance();
cacheManager = CacheManager.newInstance("./src/main/resources/ehcache.xml");
InputStream inputStream = new FileInputStream(new File("./src/main/resources/ehcache.xml"));
cacheManager = CacheManager.newInstance(inputStream);
String[] cacheNames = cacheManager.getCacheNames(); // [HelloWorldCache]
四:Spring整合
項目結(jié)構(gòu):

4.1、pom.xml 引入spring和ehcache
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gdut.yh</groupId>
<artifactId>EhcacheSpringTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.10</junit.version>
<spring.version>4.2.3.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- springframework -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.3</version>
</dependency>
</dependencies>
</project>
4.2、在src/main/resources添加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">
<!-- 磁盤緩存位置 -->
<diskStore path="java.io.tmpdir/ehcache" />
<!-- 默認(rèn)緩存 -->
<defaultCache
maxEntriesLocalHeap="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
maxEntriesLocalDisk="10000000"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU">
<persistence strategy="localTempSwap"/>
</defaultCache>
<!-- helloworld緩存 -->
<cache name="HelloWorldCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="5"
timeToLiveSeconds="5"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
<cache name="UserCache"
maxElementsInMemory="1000"
eternal="false"
timeToIdleSeconds="1800"
timeToLiveSeconds="1800"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"/>
</ehcache>
4.3、在src/main/resources/conf/spring中配置spring-base.xml和spring-ehcache.xml
spring-base.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"
xmlns:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:component-scan base-package="com.gdut.*"/>
</beans>
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"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/cache
http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">
<description>ehcache緩存配置管理文件</description>
<!-- 啟用緩存注解開關(guān) -->
<cache:annotation-driven cache-manager="cacheManager"/>
<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>
4.4、在src/main/java/com.mengdee.manager.service/下 創(chuàng)建EhcacheService和EhcacheServiceImpl
EhcacheService.java
public interface EhcacheService {
// 測試失效情況,有效期為5秒
public String getTimestamp(String param);
public String getDataFromDB(String key);
public void removeDataAtDB(String key);
public String refreshData(String key);
public User findById(String userId);
public boolean isReserved(String userId);
public void removeUser(String userId);
public void removeAllUser();
}
EhcacheServiceImpl.java
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service
public class EhcacheServiceImpl implements EhcacheService{
// value的值和ehcache.xml中的配置保持一致
@Cacheable(value="HelloWorldCache", key="#param")
public String getTimestamp(String param) {
Long timestamp = System.currentTimeMillis();
return timestamp.toString();
}
@Cacheable(value="HelloWorldCache", key="#key")
public String getDataFromDB(String key) {
System.out.println("從數(shù)據(jù)庫中獲取數(shù)據(jù)...");
return key + ":" + String.valueOf(Math.round(Math.random()*1000000));
}
@CacheEvict(value="HelloWorldCache", key="#key")
public void removeDataAtDB(String key) {
System.out.println("從數(shù)據(jù)庫中刪除數(shù)據(jù)");
}
@CachePut(value="HelloWorldCache", key="#key")
public String refreshData(String key) {
System.out.println("模擬從數(shù)據(jù)庫中加載數(shù)據(jù)");
return key + "::" + String.valueOf(Math.round(Math.random()*1000000));
}
// ------------------------------------------------------------------------
@Cacheable(value="UserCache", key="'user:' + #userId")
public User findById(String userId) {
System.out.println("模擬從數(shù)據(jù)庫中查詢數(shù)據(jù)");
return new User(1, "mengdee");
}
@Cacheable(value="UserCache", condition="#userId.length()<12")
public boolean isReserved(String userId) {
System.out.println("UserCache:"+userId);
return false;
}
//清除掉UserCache中某個指定key的緩存
@CacheEvict(value="UserCache",key="'user:' + #userId")
public void removeUser(String userId) {
System.out.println("UserCache remove:"+ userId);
}
//allEntries:true表示清除value中的全部緩存,默認(rèn)為false
//清除掉UserCache中全部的緩存
@CacheEvict(value="UserCache", allEntries=true)
public void removeAllUser() {
System.out.println("UserCache delete all");
}
}
User .java
public class User {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public User() {
}
public User(int id, String name) {
super();
this.id = id;
this.name = name;
}
@Override
public String toString() {
return "User [id=" + id + ", name=" + name + "]";
}
}
#注解基本使用方法
Spring對緩存的支持類似于對事務(wù)的支持。
首先使用注解標(biāo)記方法,相當(dāng)于定義了切點,然后使用Aop技術(shù)在這個方法的調(diào)用前、調(diào)用后獲取方法的入?yún)⒑头祷刂?,進而實現(xiàn)了緩存的邏輯。
@Cacheable
表明所修飾的方法是可以緩存的:當(dāng)?shù)谝淮握{(diào)用這個方法時,它的結(jié)果會被緩存下來,在緩存的有效時間內(nèi),以后訪問這個方法都直接返回緩存結(jié)果,不再執(zhí)行方法中的代碼段。
這個注解可以用condition屬性來設(shè)置條件,如果不滿足條件,就不使用緩存能力,直接執(zhí)行方法。
可以使用key屬性來指定key的生成規(guī)則。
@Cacheable 支持如下幾個參數(shù):
- value:緩存位置名稱,不能為空,如果使用EHCache,就是ehcache.xml中聲明的cache的name, 指明將值緩存到哪個Cache中
- key:緩存的key,默認(rèn)為空,既表示使用方法的參數(shù)類型及參數(shù)值作為key,支持SpEL,如果要引用參數(shù)值使用井號加參數(shù)名,如:#userId,一般來說,我們的更新操作只需要刷新緩存中某一個值,所以定義緩存的key值的方式就很重要,最好是能夠唯一,因為這樣可以準(zhǔn)確的清除掉特定的緩存,而不會影響到其它緩存值 ,本例子中使用實體加冒號再加ID組合成鍵的名稱,如"user:1"、"order:223123"等
- condition:觸發(fā)條件,只有滿足條件的情況才會加入緩存,默認(rèn)為空,既表示全部都加入緩存,支持SpEL
// 將緩存保存到名稱為UserCache中,鍵為"user:"字符串加上userId值,如 'user:1'
@Cacheable(value="UserCache", key="'user:' + #userId")
public User findById(String userId) {
return (User) new User("1", "mengdee");
}
// 將緩存保存進UserCache中,并當(dāng)參數(shù)userId的長度小于12時才保存進緩存,默認(rèn)使用參數(shù)值及類型作為緩存的key
// 保存緩存需要指定key,value, value的數(shù)據(jù)類型,不指定key默認(rèn)和參數(shù)名一樣如:"1"
@Cacheable(value="UserCache", condition="#userId.length() < 12")
public boolean isReserved(String userId) {
System.out.println("UserCache:"+userId);
return false;
}
@CachePut
與@Cacheable不同,@CachePut不僅會緩存方法的結(jié)果,還會執(zhí)行方法的代碼段。它支持的屬性和用法都與@Cacheable一致。
@CacheEvict
與@Cacheable功能相反,@CacheEvict表明所修飾的方法是用來刪除失效或無用的緩存數(shù)據(jù)。
@CacheEvict 支持如下幾個參數(shù):
- value:緩存位置名稱,不能為空,同上
- key:緩存的key,默認(rèn)為空,同上
- condition:觸發(fā)條件,只有滿足條件的情況才會清除緩存,默認(rèn)為空,支持SpEL
- allEntries:true表示清除value中的全部緩存,默認(rèn)為false
//清除掉UserCache中某個指定key的緩存
@CacheEvict(value="UserCache",key="'user:' + #userId")
public void removeUser(User user) {
System.out.println("UserCache"+user.getUserId());
}
//清除掉UserCache中全部的緩存
@CacheEvict(value="UserCache", allEntries=true)
public final void setReservedUsers(String[] reservedUsers) {
System.out.println("UserCache deleteall");
}
5、測試
SpringTestCase.java
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration(locations = {"classpath:spring-base.xml","classpath:spring-ehcache.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class SpringTestCase extends AbstractJUnit4SpringContextTests{
}
EhcacheServiceTest.java
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.gdut.ehcache.EhcacheService;
public class EhcacheServiceTest extends SpringTestCase{
@Autowired //@Autowired 是通過 byType 的方式去注入的, 使用該注解,要求接口只能有一個實現(xiàn)類。
private EhcacheService ehcacheService;
// 有效時間是5秒,第一次和第二次獲取的值是一樣的,因第三次是5秒之后所以會獲取新的值
@Test
public void testTimestamp() throws InterruptedException{
System.out.println("第一次調(diào)用:" + ehcacheService.getTimestamp("param"));
Thread.sleep(2000);
System.out.println("2秒之后調(diào)用:" + ehcacheService.getTimestamp("param"));
Thread.sleep(4000);
System.out.println("再過4秒之后調(diào)用:" + ehcacheService.getTimestamp("param"));
}
@Test
public void testCache(){
String key = "zhangsan";
String value = ehcacheService.getDataFromDB(key); // 從數(shù)據(jù)庫中獲取數(shù)據(jù)...
ehcacheService.getDataFromDB(key); // 從緩存中獲取數(shù)據(jù),所以不執(zhí)行該方法體
ehcacheService.removeDataAtDB(key); // 從數(shù)據(jù)庫中刪除數(shù)據(jù)
ehcacheService.getDataFromDB(key); // 從數(shù)據(jù)庫中獲取數(shù)據(jù)...(緩存數(shù)據(jù)刪除了,所以要重新獲取,執(zhí)行方法體)
}
@Test
public void testPut(){
String key = "mengdee";
ehcacheService.refreshData(key); // 模擬從數(shù)據(jù)庫中加載數(shù)據(jù)
String data = ehcacheService.getDataFromDB(key);
System.out.println("data:" + data); // data:mengdee::103385
ehcacheService.refreshData(key); // 模擬從數(shù)據(jù)庫中加載數(shù)據(jù)
String data2 = ehcacheService.getDataFromDB(key);
System.out.println("data2:" + data2); // data2:mengdee::180538
}
@Test
public void testFindById(){
ehcacheService.findById("2"); // 模擬從數(shù)據(jù)庫中查詢數(shù)據(jù)
ehcacheService.findById("2");
}
@Test
public void testIsReserved(){
ehcacheService.isReserved("123");
ehcacheService.isReserved("123");
}
@Test
public void testRemoveUser(){
// 線添加到緩存
ehcacheService.findById("1");
// 再刪除
ehcacheService.removeUser("1");
// 如果不存在會執(zhí)行方法體
ehcacheService.findById("1");
}
@Test
public void testRemoveAllUser(){
ehcacheService.findById("1");
ehcacheService.findById("2");
ehcacheService.removeAllUser();
ehcacheService.findById("1");
ehcacheService.findById("2");
// 模擬從數(shù)據(jù)庫中查詢數(shù)據(jù)
// 模擬從數(shù)據(jù)庫中查詢數(shù)據(jù)
// UserCache delete all
// 模擬從數(shù)據(jù)庫中查詢數(shù)據(jù)
// 模擬從數(shù)據(jù)庫中查詢數(shù)據(jù)
}
}
以上所述是小編給大家介紹的Java進程內(nèi)緩存框架EhCache詳解,希望對大家有所幫助。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關(guān)文章
Java8函數(shù)式接口Predicate用法示例詳解
這篇文章主要為大家介紹了Java8函數(shù)式接口Predicate用法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-07-07
Java并發(fā)編程示例(七):守護線程的創(chuàng)建和運行
這篇文章主要介紹了Java并發(fā)編程示例(七):守護線程的創(chuàng)建和運行,在本節(jié)示例中,我們將創(chuàng)建兩個線程,一個是普通線程,向隊列中寫入事件,另外一個是守護線程,清除隊列中的事件,需要的朋友可以參考下2014-12-12
Java實現(xiàn)終止線程池中正在運行的定時任務(wù)
本篇文章給大家分享了JAVA中實現(xiàn)終止線程池中正在運行的定時任務(wù)的具體步驟和方法,有需要的朋友跟著學(xué)習(xí)下。2018-05-05
IDEA新建javaWeb以及Servlet簡單實現(xiàn)小結(jié)
這篇文章主要介紹了IDEA新建javaWeb以及Servlet簡單實現(xiàn)小結(jié),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-11-11
Spring-cloud-eureka使用feign調(diào)用服務(wù)接口
這篇文章主要為大家詳細(xì)介紹了Spring-cloud-eureka使用feign調(diào)用服務(wù)接口,具有一定的參考價值,感興趣的小伙伴們可以參考一下2019-04-04
SpringBoot整合MyBatis實現(xiàn)CRUD操作項目實踐
本文主要介紹了SpringBoot整合MyBatis實現(xiàn)CRUD操作項目實踐,如何實現(xiàn)數(shù)據(jù)庫的CRUD創(chuàng)建、讀取、更新、刪除操作,具有一定的參考價值,感興趣的可以了解一下2024-02-02

