I am making caching solution for a method located in a servlet.
Servlet looks like following:
public class DataOptimizedServlet extends DataServlet {
...
@Override
@Cacheable(value = "dataOptimized", key = "#req.getRequestURI()")
public byte[] getData(HttpServletRequest req) {
// data retrieval logic
}
...
}
in ehcache.xml I have following configuration:
<cache alias="dataOptimized">
<expiry>
<ttl unit="hours">30</ttl>
</expiry>
<resources>
<heap unit="entries">20000</heap>
<offheap unit="MB">200</offheap>
</resources>
</cache>
Also in ctx-cache.xml
file is following configuration (and this file is imported in web.xml
):
<cache:annotation-driven cache-manager="ehCacheManager" />
<bean id="ehCacheManager" class="org.springframework.cache.jcache.JCacheCacheManager">
<property name="cacheManager">
<bean class="org.springframework.cache.jcache.JCacheManagerFactoryBean" p:cacheManagerUri="classpath:ehcache.xml" />
</property>
</bean>
But it does not work, method getData
still gets hit for the same URLs. I have many @Cacheables
working in a project and configured in the same manner, but none is in servlet directly (they're in services).
What am I missing?