SpringBoot ehcache 간단 정리

개발/SPRING2021. 12. 22. 22:16
728x90

 

 

SpringBoot ehcache 간단히 정리

@EnableCaching 

  • Spring Boot Applicatoin 설정에 @EnableCaching 을 추가한다. 
@SpringBootApplication
@EnableCaching
public class ApiApplication {
	public static void main(String[] args) {
		SpringApplication.run(ApiApplication.class, args);
	}
}

ehcache.xml 작성

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"
         updateCheck="false">
    <diskStore path="java.io.tmpdir" />

   <cache name="blacklist"
           maxEntriesLocalHeap="10000"
           maxEntriesLocalDisk="1000"
           eternal="false"
           diskSpoolBufferSizeMB="20"
           timeToIdleSeconds="300" timeToLiveSeconds="6000"
           memoryStoreEvictionPolicy="LFU"
           transactionalMode="off">
        <persistence strategy="localTempSwap" />
    </cache>
 </ehcache>

@Cacheable

ehcache에 설정한 name을  value 값으로 입력한다. 

	@Cacheable(value = "blacklist", key="#key")
	public ArrayList<String> getBlackList(int key) {
		return mapper.getBlacklistWord();
	}

 

 

728x90

작성자

Posted by 일퍼센트

관련 글

댓글 영역