목차 >> Cache Manager 
+- GlueCacheManager  
+- GlueEhCacheManager  
----+- cache name

8장 Cache Manager

GlueEhCacheManager

Glue Project 생성시 EhCache 를 사용하는 것으로 구성되어 있습니다. 다음은 EhCache 관련 리소스입니다.

  • applicationContext.xml
  • ehcache.xml
  • library : ehcache-core
    applicationContext.xml의 일부
    <bean id="cacheManager" class="com.poscoict.glueframework.cache.ecache.GlueEhCacheManager"/>
    
    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" name="__DEFAULT__">
        <cache name="_default-region" maxElementsInMemory="500" eternal="true" />
        <cache name="_sql-region" maxElementsInMemory="500" eternal="true" />
        <cache name="_message-definition-region" maxElementsInMemory="500" eternal="true" />
        <cache name="_service-region" maxElementsInMemory="500" eternal="true" />
        <cache name="_column-region" maxElementsInMemory="500" eternal="true" />
    </ehcache>
    
    pom.xml의 일부
    <dependency>
        <groupId>com.poscoict</groupId>
        <artifactId>glue-core</artifactId>
        <version>${glue-version}</version>
    </dependency>
    <dependency>
        <groupId>net.sf.ehcache</groupId>
        <artifactId>ehcache-core</artifactId>
        <version>${ehcache-version}</version>
    </dependency>
    

추가적인 cache name

다음 예제와 같이 cacheRegion을 사용하고자 할 경우, ehcache.xml의 <cache> 을 추가합니다. 다음 예제의 경우 <cache name="biz_region" /> 이 추가될 것입니다.

public class SampleActivity extends GlueActivity<GlueContext> {
    @Override
    public String runActivity( GlueContext ctx ) {
        GlueCacheManager cacheManager
            = GlueStaticContext.getBeanFactory().getBeanObject( "cacheManager", GlueCacheManager.class );
        GlueCacheLoader cacheLoader
            = GlueStaticContext.getBeanFactory().getBeanObject( "bizCacheLoader", GlueCacheLoader.class );
        String cacheKey = "key";
        String cacheRegion = "biz_region";
        Object data = cacheManager.getCacheObject(cacheKey, cacheRegion, cacheLoader);
        . . .
        return GlueBizControlConstants.SUCCESS;
    }
}

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" name="__DEFAULT__">
    <cache name="_default-region" maxElementsInMemory="500" eternal="true" />
    <cache name="_service-region" maxElementsInMemory="500" eternal="true" />
    <cache name="biz_region" maxElementsInMemory="500" eternal="true" />
</ehcache>
중략
[main] DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from ehcache.xml found in the classpath: file:/C:/eclipse/workspace/sample-parent/sample-hello-ehcache/target/classes/ehcache.xml
[main] DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from URL: file:/C:/eclipse/workspace/sample-parent/sample-hello-ehcache/target/classes/ehcache.xml
[main] DEBUG net.sf.ehcache.config.ConfigurationFactory - Configuring ehcache from InputStream
중략
[main] INFO  com.poscoict.glueframework.cache.ehcache.GlueEhCacheManager - start EhCache CacheManger : __DEFAULT__
[main] DEBUG com.poscoict.glueframework.cache.ehcache.GlueEhCacheManager - [_default-region, biz_region, _service-region]    
중략