2011-09-14 2 views
2

나는 두 개의 다른 서비스를 autowire하는 Spring에 인터셉터를 가지고있다. 두 서비스 모두 ehcache-spring-annotations 프로젝트의 @Cacheable 태그가 붙은 메소드가 있지만 cacheNames은 다릅니다.@Cachable 주석이 달린 메서드가 EHCache로 결과를 캐시하지 않는 이유는 무엇입니까?

public class MenuInterceptor extends HandlerInterceptorAdapter { 
    @Autowired 
    private EventService eventService; 

    @Autowired 
    private OrganisationInfoService orgService; 

    @Override 
    public final void postHandle(HttpServletRequest request, 
         HttpServletResponse response, 
         Object handler, 
         ModelAndView modelAndView) throws SystemException { 
     eventService.getFolderEventsForUser(123); 
     orgService.getOrgCustomProfile("abc"); 

    } 

@Service 
public class EventServiceImpl implements EventService { 
    @Override 
    @Cacheable(cacheName = "ecomOrders") 
    public Collection<FolderEventBean> getFolderEventsForUser(long loginId) throws SystemException { 


@Service("organisationInfoService") 
public class OrganisationInfoServiceImpl implements OrganisationInfoService { 
    @Override 
    @Cacheable(cacheName="orgProfile") 
    public OrgCustomProfileBean getOrgCustomProfile(String orgHierarchyString) throws ServiceException { 

응용 프로그램을 실행할 때 한 메서드는 결과에 EHCache를 사용하지만 다른 메서드는 사용하지 않습니다. EventServiceImpl.getFolderEvnetsForUser은 그렇지 않지만 OrganisationInfoSericeImpl.getOrgCustomProfile() 캐시는 올바르게 캐시됩니다. 누군가 제발 말해 줄래?

두 서비스 모두 동일한 캐시를 사용하려고했지만 여전히 그 중 하나만 작동합니다. 난으로 Ehcache 스프링 - 주석 DEBUG 온하고, 시동시 두 방법 모두를 등록

[DEBUG] 8시 9분 1초() 속성 CACHE 의뢰 방법 'getFolderEventsForUser'를 가산 : CacheableAttributeImpl [캐시 = [이름 = ecomOrders 상태 = STATUS_ALIVE 이터널 = 거짓 overflowToDisk = false maxElementsOnDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 300 timeToIdleSeconds = 0 diskPersistent = false diskExpiryThreadIntervalSeconds = 120 cacheEventListeners : net.sf.ehcache.statistics.LiveCacheStatisticsWrapper hitCount = 0 memoryStoreHitCount = 0 diskStoreHitCount = 0 missCountNotFound = 0 missCountExpired = 0], cacheKeyGenerator = HashCodeCacheKeyGenerator [includeMethod = true, includeParameterTypes = true, useReflection = false, checkforCycle S = 거짓, entryFactory = NULL, exceptionCache = NULL, parameterMask = ParameterMask [마스크 = [] [] com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute (CacheAttributeSourceImpl.java:174)에서

[DEBUG] 08:09:01() 캐시 속성 권고 : CacheableAttributeImpl [캐시 = [이름 = orgProfile 상태 = STATUS_ALIVE 이터널 = 거짓 overflowToDisk = false maxElementsInMemory = 200 maxElementsOnDisk = 0 memoryStoreEvictionPolicy = LRU timeToLiveSeconds = 86400 timeToIdleSeconds = 0 diskPersistent = false diskExpiryThreadIntervalSeconds = 120 cacheEventListeners : net.sf.ehcache.statistics.LiveCacheStatisticsWrapper hitCount = 0 memoryStoreHitCount = 0 diskStoreHitCount = 0 missCountNotFound = 0 missCountExpired = 0], cacheKeyGenerator = HashCodeCacheKeyGenerator [includeMethod = true, useParameterTypes = true, useRef com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute (CacheAttributeSourceImpl.java:174)에서 parameter_task = false, checkforCycles = false], entryFactory = null, 예외 캐시 = null, 매개 변수 마스크 = 매개 변수 마스크 [ 인터셉터는 autowire가 서비스를 호출 할 때

, 그 중 하나는 캐시 :

[DEBUG] 8시 9분 19초 (UNIQUE_ID) 호출을위한 생성 키 '-1668638847278617'ReflectiveMethodInvocation : 추상적 공개 no.finntech.base.modules.organisation.support.OrgCustomProfileBean no.finntech.service.organisation.OrganisationInfoService.getOrgCustomProfile (java.lang.String) throws no.finntech.service.ServiceEx 선거; 대상은 [no.finntech.service.organisation.impl.OrganisationInfoServiceImpl] [URI :/finn/minfinn/myitems/list, 원격 IP : 127.0.0.1, 참조 자 :, 사용자 에이전트 : Mozilla/5.0 (Windows NT 6.1 ; WOW64; RV : 6.0.2) 도마뱀/com.googlecode.ehcache.annotations.interceptor.EhCacheInterceptor.generateCacheKey의 파이어 폭스 20,100,101/6.0.2 (EhCacheInterceptor.java:272)

EDIT : I 정상적으로 아마도 두 서비스가 서로 다른 모듈에 정의되어 있다고 언급 할 수 있습니다.

답변

3

그것은 이유가 문맥에 관련이 밝혀졌습니다. 캐시에 실패한 서비스가 두 가지 다른 구성 요소 검사에 포함되었습니다. 최대한 빨리 캐싱이 예상대로 작동하는 것으로 확인되었습니다.

3

OrganisationInfoService 인터페이스를 통해 두 번째 방법을 어떻게 호출하고 있습니까?어노테이션은 인터페이스를 통해 메소드를 호출하는 데 의존하므로 캐시를 수행하는 프록시를 생성 할 수 있습니다.

외부에서 직접 또는 특정 클래스의 다른 메소드에서 호출하여 구체적인 클래스를 호출하는 경우 주석이 작동하지 않습니다.

참조는 질문에 3, 4 응답 : 구성 요소를 스캔 : http://code.google.com/p/ehcache-spring-annotations/wiki/FrequentlyAskedQuestions

+0

둘 다 각각의 인터페이스를 통해 호출됩니다. – Nicolai

+0

흠, 첫 번째 캐시에는 다른 캐시 (86400 초)와 비교하여 300 초의 timeToLive 값이 있습니다. 즉, 캐시 된 오브젝트는 마지막 액세스 시간과 상관없이 5 분 후에 축출됩니다. 따라서 메소드가 주어진 loginId에 대해서만 거의 호출되지 않으면 상황이 캐시되지 않은 것처럼 보일 것입니다. 이유가 있을까요? – Paolo

+0

현재로서는 이것을 테스트하고 캐시 된 것인지 확인하고 있습니다. 전화는 서로 몇 초 안에 이루어집니다. 캐시 프록시는 EventService에 절대 사용되지 않으므로 일종의 설치/구성 문제가 있어야합니다. – Nicolai