
src/conf/applicationContext-local-cache.xml
Spring 프레임워크를 사용하는 자바 애플리케이션에서
로컬 캐시 설정을 위해 사용된다.
Spring의 의존성 주입 기능을 활용하여
애플리케이션의 다양한 컴포넌트에 대한 구성정보를 XML 형식으로 제공한다.
설정할 수 있는 것
1. 캐시 매니저 정의
캐시를 관리하기 위한 컴포넌트를 설정
ex) ehCache, Guava Cache, Hazelcast 등 다양한 캐시 구현체를 사용할 수 있다.
2. 캐시 성질 설정
이름, 만료시간, 메모리 한계, 캐시에 저장될 객체의 최대 개수 등
캐시의 동작 방식을 세부적으로 설정할 수 있다.
3. 캐시 사용을 위한 빈
캐시를 사용할 객체들을 Spring bean으로 등록하여
의존성 주입을 통해 캐시를 사용할 수 있도록 한다.
<?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.xsd">
<bean id="localCacheManager" 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"/>
<property name="shared" value="false"/>
</bean>
</beans>
<bean id="localCacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
: 이 빈 정의는 EhCache를 사용하는 캐시 매니저를 애플리케이션의 캐시 매니저로 설정합니다.
<property name="cacheManager" ref="ehcache"/>
: localCacheManager 빈에 대한 속성 설정입니다.
이는 ehcache라는 ID를 가진 빈을 cacheManager 속성에 주입합니다.
여기서 ref 속성은 다른 빈의 ID를 참조합니다.
<bean id="ehcache" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
: EhCache 매니저의 팩토리 빈을 정의합니다.
이 빈은 EhCache 구성을 로드하고 초기화하는 역할을 담당합니다.
<property name="configLocation" value="classpath:ehcache.xml"/>
: EhCache 설정 파일의 위치를 지정합니다.
classpath:ehcache.xml은 클래스패스에서 ehcache.xml 파일을 찾아 사용하라는 의미입니다.
이 파일에는 캐시의 이름, 메모리 설정, 디스크 저장소 설정 등 EhCache의 세부 설정이 포함됩니다.
<property name="shared" value="false"/>
: EhCache 인스턴스가 여러 캐시 매니저 간에 공유되는지 여부를 지정합니다.
false는 각 캐시 매니저가 자신만의 EhCache 인스턴스를 가지고 있음을 의미합니다.
src/conf/ehcache.xml
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false"
monitoring="off" dynamicConfig="false">
<cache
name="pushnoti_send_status"
maxEntriesLocalHeap="1000"
eternal="false"
memoryStoreEvictionPolicy="LRU"
timeToLiveSeconds="600"
transactionalMode="off">
<persistence strategy="none" />
</cache>
</ehcache>
applicationContext-cache.xml 은 applicationContext-local-cache.xml 랑 뭐가 다른거야?
applicationContext-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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
<property name="caches">
<set>
<bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
p:name="batch"/>
</set>
</property>
</bean>
</beans>
캐시 매니저: SimpleCacheManager를 사용합니다.
이는 Spring에서 제공하는 가장 기본적인 캐시 매니저 중 하나로, 간단한 캐싱 시나리오에 적합합니다.
캐시 구현체: ConcurrentMapCacheFactoryBean을 사용하여 ConcurrentMap 기반의 캐시를 생성합니다.
이는 자바의 ConcurrentMap을 사용하여 메모리 내 캐싱을 제공하며, 복잡한 설정 없이 간단한 캐싱 요구 사항에 적합합니다.
캐시 이름: 이 구성 파일에서는 "batch"라는 이름의 캐시를 정의합니다.
이는 애플리케이션 내에서 특정 데이터를 캐싱하는 데 사용될 수 있습니다.
차이점 요약
캐시 매니저와 구현체
: applicationContext-cache.xml은 간단한 캐싱을 위한 SimpleCacheManager와 ConcurrentMapCacheFactoryBean을 사용하는 반면,
applicationContext-local-cache.xml은 보다 복잡한 캐싱 시나리오를 위해 EhCacheCacheManager와 EhCache를 사용합니다.
설정의 복잡성과 기능성
: EhCache를 사용하는 설정은 보다 고급 캐싱 기능과 세부적인 설정을 제공하는 반면,
SimpleCacheManager와 ConcurrentMapCache 기반의 설정은 간단한 사용 사례에 더 적합합니다.
용도와 선호도
: 애플리케이션의 캐싱 요구 사항이 복잡하고 세밀한 제어가 필요한 경우 EhCache를 사용하는 것이 좋으며,
간단한 캐싱을 원하는 경우 SimpleCacheManager와 ConcurrentMapCache가 더 적합할 수 있습니다.
applicationContext-datasource.xml
데이터 소스, 데이터베이스 연결 풀을 구성하기 위한 설정 파일이다.
이 파일은 HikariCP를 사용하여 다양한 데이터 소스를 정의하고, 구성한다.
HikariCP는 고성능 JDBC 커넥션 풀 라이브러리이다.
java db connect
jdbc.driverClassName=software.aws.rds.jdbc.mysql.Driver
jdbc.log.0.url=jdbc:mysql:aws://127.0.0.1:27721/db_ddc2_local_shard_0?maxAllowedPacket=10485760&zeroDateTimeBehavior=CONVERT_TO_NULL&verifyServerCertificate=false&useSSL=false&allowPublicKeyRetrieval=true


<value>classpath*:com/ddc2/admin/mybatis/log/dao/*.xml</value>


'학습 기록 (Learning Logs) > Today I Learned' 카테고리의 다른 글
Map 함수 (0) | 2024.08.14 |
---|---|
Redis, Spring (0) | 2024.08.07 |
Spring Security? OAuth2 ? (0) | 2024.08.06 |
MSA, Spring Cloud (0) | 2024.08.06 |
DI, IoC (0) | 2024.07.30 |