'캐싱'에 해당되는 글 1건

  1. 2015.08.12 [Spring] ehcache 캐싱하기

EHcache (eh-cache) 캐싱이란?


같은 데이터를 계속 DB에 조회하는 경우가 있다.

이런 경우 메모리나 디스크에 저장하여 DB를 조회하지 않고 메모리를 사용하여 성능을 대폭적으로 향상시킨다.

그래서 분산캐시사용한다. !!!!


EHcache의 주요 특징 

- 경량의 빠른 캐시 엔진

- 확장 - 메모리,디스크 저장 지원, 멀티 CPU 동시 접근에 튜닝

- 분산지원!! - 동기/비동기 복사,피어자동발견

- 높은 품질 


분산캐시란 ? 

서버가 두개면 url 두번 호출하게 되는데 분산캐시는 url 한번 호출한다.


그럼 Spring framework 에서는 어떻게 사용하는지 알아보자.


기본적으로 아래와 같은 작업이 필요하다.

ehcache 설치 -> 캐시 설정 파일 작성 -> cacheManager 생성 ->

cacheManager 로 구한 cache 를 이용한 CRUD -> cacheManager 종료

 

 

ehcache 사용하기 위한 설정


1.스프링 서블릿 설정파일 (servlet.xml) 

<beans>에

xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring" 

추가하고 아래 URL를 추가한다.

http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring

http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.2.xsd



위의 <bean>추가 해주면 서블릿 설정파일에서 할일은 끝!


2. ehcache 설정 파일을 생성( ehcache.xml )


name = 캐시이름

maxElementsInMemory = 최대메모리용량

timeToLiveSeconds = 저장되는 시간(초단위) (3600 :한시간)


3. @Cacheable(cacheName="캐시이름") 을 캐시할 메소드 위에 어노테이션 사용하면 끝!



위와 같이 해주면 getpcBangIps 메소드는 pcBangIps 캐시를 사용하여 한시간마다 메모리에 데이터가 저장된다. 




'FRAMEWORK > Spring' 카테고리의 다른 글

Spring scheduler 설정 및 사용  (0) 2016.04.12
스프링 이클립스 연동하기  (0) 2015.10.20
aop 예제  (0) 2015.08.24
aop  (0) 2015.08.23
Spring @PathVariable 이용하여 parameter 를 url 형식으로 받기  (0) 2015.08.13
Posted by 양승아
: