사용자 도구

사이트 도구


java:simple-spring-memcached

문서의 이전 판입니다!


Simple Spring Memcached

설정

  • @EnableAspectJAutoProxy가 필수적으로 돼 있어야 한다.

Cache Name을 key Prefix로 사용하기

  • SSM은 하나의 Memcached 서버군에서 여러 Cache Name을 사용할 경우에도 기본적으로 CacheName을 Key의 prefix로 붙이지 않아서, 여러 CacheName에서 동일한 Cache Key를 사용할 경우 키 충돌이 발생할 수 있다.
  • 해당 문제는 특히 Spring Cacheh Abstraction과 함께 사용할 경우 심각한 키 충돌을 일으키게 된다.
  • 3.3.0 패치에 따라 이 이후부터 CacheConfiguration.useNameAsKeyPrefix 프라퍼티를 true로 설정하여 해결 가능해졌다.
    @Bean
    public CacheConfiguration coupangCacheConfiguration() {
        CacheConfiguration cacheConfiguration = new CacheConfiguration();
        cacheConfiguration.setConsistentHashing(true);
        cacheConfiguration.setUseBinaryProtocol(true);
        cacheConfiguration.setOperationTimeout(operationTimeout);
     
        // Cache Name Key Prefix 부분
        cacheConfiguration.setUseNameAsKeyPrefix(true);
        cacheConfiguration.setKeyPrefixSeparator(":");
        return cacheConfiguration;
    }
  • Memcached 버전에 따라 Key 문자열에 #이 오는 것을 허용하지 않는 듯 하다.

임시 Cache 무력화

  • ssm.cache.disable=true System Property 지정을 통해 캐시를 임시로 무력화할 수 있다.
    -Dssm.cache.disable=true

주의

  • Annotation은 Class 레벨에 붙이도록 한다. Interface에 어노테이션 하는 것은 작동하지 않는다.
  • com.google.code.ssm.CacheFactory 객체 로딩이 <import resource=“classpath:simplesm-context.xml” /> 보다 먼저 이뤄져야 한다.
  • 최소한 한 개의 default라는 이름의 캐시가 존재해야 한다. 그렇지 않으면 매번 @CacheName 어노테이션으로 캐시 이름을 지정해줘야 한다.
  • @CacheKeyMethod 사용시 @CacheKey뿐만 아니라 equals/hashCode 등을 통한 값 비교도 행해진다. 따라서 올바른 equals/hashCode도 생성해 두어야 한다.
java/simple-spring-memcached.1429256409.txt.gz · 마지막으로 수정됨: 2015/04/17 16:40 저자 kwon37xi