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

8장 Cache Manager

GlueEhCacheManager

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

  • applicationContext.xml : cacheManager는 Java Doc을 참고해서 설정합니다. (GlueAPI)

  • ehcache.xml : xml 파일은 ehcache.xsd를 준수해서 작성합니다.

  • library : ehcache

    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</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]
중략

RMI를 이용한 Cache 복제

자세한 것은 EhCache의 Documentation을 참고합니다.

  • http://ehcache.org/documentation/2.6/replication/rmi-replicated-caching
    <?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" monitoring="autodetect" name="__DEFAULT__">
    
        <cacheManagerPeerProviderFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory"
            properties="peerDiscovery=manual, 
                        rmiUrls=//server2:12345/cache1
                               |//server2:12345/cache2" />
        <cacheManagerPeerListenerFactory
            class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
            properties="hostName=localhost,port=12345,socketTimeoutMillis=120000" />
        <cache name="_default-region" maxElementsInMemory="500" eternal="true">
            <cacheEventListenerFactory 
               class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" 
               properties="replicateUpdatesViaCopy=true,replicateUpdates=true" />
        </cache>
        <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>
    

^L

Prev Home Next