티스토리 뷰
jdk 7, egovframework 3.8 (spring 4.3)
1. pom.xml에 dependency 추가
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.9</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
2. 캐시 설정 추가 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">
<defaultCache
eternal="false"
maxElementsInMemory="50"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="100"
timeToLiveSeconds="200"
memoryStoreEvictionPolicy="LRU" />
<cache
name="globalMenuCache"
eternal="false"
maxElementsInMemory="100"
overflowToDisk="false"
diskPersistent="false"
timeToIdleSeconds="0"
timeToLiveSeconds="0"
memoryStoreEvictionPolicy="LRU" />
</ehcache>
- name : 캐시의 이름이다. @Cacheable("캐시의 이름") 와 일치시켜줘야한다.
- eternal : 한번 캐시하면 영원히 유지할 것인지의 여부
- maxElementsInMemory : 메모리에 보유할 최대 오브젝트 수
- overflowToDisk : 메모리저장공간이 부족할때 Disk 사용여부( true,false )
- diskPersistent : flush시에 파일로 저장 여부 ( trun , false )
- timeToIdleSeconds : 데이터가 지정된 시간(초단위)동안 재호출되지 않으면 휘발됨
- timeToLiveSeconds : 한번 저장된 데이터의 최대 저장 유지 시간(초단위)
- memoryStoreEvictionPolicy : FIFO-가장 먼저 적재된 페이지 교체, LFU-가장 적은 참조횟수를 갖는 페이지를 교체, LRU 가장 오랫동안 참조되지 않은 페이지를 교체
3. 캐시 서비스 추가
package egovframework.sample.menu.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@Service("sampleMenuService")
public class SampleMenuService {
@Resource
SampleMenuMapper sampleMenuMapper;
@Cacheable(value="globalMenuCache")
public List globalMenuList(HttpServletRequest request) throws Exception {
return sampleMenuMapper.globalMenuList(pMap);
}
}
3. context-cache.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"
xmlns:cache="http://www.springframework.org/schema/cache"
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
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">
<cache:annotation-driven />
<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:egovframework/디렉토리/ehcache.xml"/>
</bean>
</beans>
참고: https://thereclub.tistory.com/10
끝.
'웹개발자 > java' 카테고리의 다른 글
전자정부프레임워크 트랜잭션 처리 (0) | 2020.05.27 |
---|---|
전자정부프레임워크 hibernate-validator 적용 (spring 4.3) (0) | 2020.03.02 |
이미지 업로드 가로 세로 회전 현상 처리 (0) | 2020.03.01 |
java 썸네일 생성 (0) | 2020.03.01 |
전자정부프레임워크 3.8 task 추가 (스프링프레임워크 4) (0) | 2019.11.08 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- autohotkey
- Spring Boot
- 구글 플레이 게임즈
- 시즌3
- 윈도우
- 달빛조각사
- 호이안
- 블루스택
- 전자정부프레임워크
- 설치
- 메소드 제한
- 설정
- 오토핫키
- 배드워즈
- lineage2m
- mysql
- download
- nginx
- 베트남
- 로블록스
- tomcat
- 단축키
- 라즈베리파이
- mariaDB
- eGovFramework
- Spring
- 시즌패스
- 다운로드
- 수원
- java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함