Spring には、2 つの異なるサービスを自動配線するインターセプターがあります。どちらのサービスにも@Cacheable
、ehcache-spring-annotations プロジェクトの でタグ付けされたメソッドがありますが、 は異なりcacheNames
ます。
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 が正常に使用され、もう一方の方法では使用されません。はOrganisationInfoSericeImpl.getOrgCustomProfile()
正しくキャッシュしますが、 はキャッシュEventServiceImpl.getFolderEvnetsForUser
しません。誰かが理由を教えてもらえますか?
両方のサービスで同じキャッシュを使用しようとしましたが、まだ機能するのは 1 つだけです。ehcache-spring-annotations の DEBUG をオンにすると、起動時に両方のメソッドが登録されます。
[DEBUG] 08:09:01 () 属性を持つ CACHE 推奨メソッド 'getFolderEventsForUser' を追加: CacheableAttributeImpl [cache=[ name = ecomOrders status = STATUS_ALIVE 永遠 = false overflowToDisk = false maxElementsInMemory = 100 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, checkforCycles=false], entryFactory=null, exceptionCache=null, parameterMask=ParameterMask [マスク=[]]] [] com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute(CacheAttributeSourceImpl.java:174)
[DEBUG] 08:09:01 () 属性を持つ CACHE 推奨メソッド 'getOrgCustomProfile' を追加: CacheableAttributeImpl [cache=[ name = orgProfile status = STATUS_ALIVE 永遠 = false 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、includeParameterTypes=true、useReflection= false, checkforCycles=false], entryFactory=null, exceptionCache=null, parameterMask=ParameterMask [マスク=[]]] [] com.googlecode.ehcache.annotations.impl.CacheAttributeSourceImpl.getMethodAttribute(CacheAttributeSourceImpl.java:174)
インターセプターが自動配線されたサービスを呼び出すと、そのうちの 1 つだけがキャッシュされます。
[DEBUG] 08:09:19 (UNIQUE_ID) 呼び出し用に生成されたキー '-1668638847278617': ReflectiveMethodInvocation: public abstract no.finntech.base.modules.organisation.support.OrgCustomProfileBean no.finntech.service.organisation.OrganisationInfoService.getOrgCustomProfile(java .lang.String) no.finntech.service.ServiceException をスローします。ターゲットはクラス [no.finntech.service.organisation.impl.OrganisationInfoServiceImpl] [URI: /finn/minfinn/myitems/list、リモート IP: 127.0.0.1、Referer: 、User-Agent: Mozilla/5.0 (Windows NT 6.1 ; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2] com.googlecode.ehcache.annotations.interceptor.EhCacheInterceptor.generateCacheKey(EhCacheInterceptor.java:272)
編集:おそらく、2 つのサービスが異なる Maven モジュールで定義されていることに言及する必要があります。