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