我的缓存注释注册,这在TRACE日志中显示:
2019-11-04 23:55:52,229 TRACE AnnotationCacheOperationSource:102 - **Adding cacheable method 'getMaximumSimilarItems'** with attribute: [Builder[public java.lang.Integer com.quote.manager.impl.SystemConfigManagerImpl.getMaximumSimilarItems()] caches=[attachments] | key='#root.methodName' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false']
@Cacheable(value = "attachments",key = "#root.methodName")
public Integer getMaximumSimilarItems() {
logger.info("GetMax");
SystemConfig systemConfig = systemConfigDao.getSystemConfig();
Integer maxSimilarItems = systemConfig.getMaximumSimilarItems();
if(maxSimilarItems != null) {
return maxSimilarItems;
}
return 20;
}
我在调用后和调用后的堆栈上看到了缓存拦截器。但是仍然没有任何缓存。我尝试了多种缓存实现。
有什么想法可以在Spring的缓存实现中的任何地方设置调试点,以弄清为什么它不缓存?
我尝试了XML config和Java Config @EnableCaching。
<bean id="cacheManager" class="org.springframework.cache.jcache.JCacheCacheManager">
<property name="cacheManager">
<bean class="org.springframework.cache.jcache.JCacheManagerFactoryBean"
p:cacheManagerUri="classpath:ehcache.xml" />
</property>
</bean>
<cache:annotation-driven cache-manager="cacheManager" />
2019-11-05 11:16:51,370 INFO Eh107CacheManager:378 - Registering Ehcache MBean javax.cache:type=CacheStatistics,CacheManager=file./home/work/workspace-quotes/.metadata/.plugins/org.eclipse.wst.server.core/tmp7/wtpwebapps/app/WEB-INF/classes/ehcache.xml,Cache=attachments
2019-11-05 11:16:51,756 INFO Eh107CacheManager:378 - Registering Ehcache MBean javax.cache:type=CacheStatistics,Cache=attachments
我看到ehCache.xml中定义的缓存也在应用程序启动时正在注册,因此缓存正在启动。
<ehcache:config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:ehcache='http://www.ehcache.org/v3'
xsi:schemaLocation="http://www.ehcache.org/v3 http://www.ehcache.org/schema/ehcache-core-3.1.xsd">
<ehcache:cache alias="attachments">
<ehcache:resources>
<ehcache:heap unit="entries">100</ehcache:heap>
<ehcache:offheap unit="MB">1</ehcache:offheap>
</ehcache:resources>
</ehcache:cache>
</ehcache:config>