Spring Cache Abstraction with Custom Cache Manager implementation not working
<p>I am trying to use a custom cache manager in spring. I have tried to implement Cache Manager and also extended AbstractCacheManager using my Custom Cache that implements Cache.
However, the caching is not working. No method from cache is being invoked.</p>

<p>I have read multiple posts but no success. May be some config issue.</p>

<p>Please help me figure this out. Thanks in advance.</p>

<p>Following are the files being used.</p>

<p>web.xml </p>

<pre><code>&lt;web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"&gt;

&lt;display-name&gt;Spring MVC Application&lt;/display-name&gt;

&lt;servlet&gt;
    &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
    &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;

&lt;servlet-mapping&gt;
    &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
    &lt;url-pattern&gt;/&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;

&lt;context-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/root-context.xml&lt;/param-value&gt;
&lt;/context-param&gt;

&lt;listener&gt;
    &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
&lt;/listener&gt;
</code></pre>

<p></p>

<p>root-context.xml</p>

<pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xsi:schemaLocation="
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"&gt;
&lt;context:annotation-config/&gt;
&lt;context:component-scan base-package="com.springapp.mvc.*"/&gt;
&lt;cache:annotation-driven/&gt;
&lt;bean id="cacheManager" class="com.springapp.mvc.cache.CustomCacheManager"/&gt;
</code></pre>

<p></p>

<p>CustomCacheManager</p>

<pre><code>public class CustomCacheManager extends AbstractCacheManager {

@Override
protected Collection&lt;? extends Cache&gt; loadCaches() {
    Collection&lt;CustomCache&gt; caches = new ArrayList&lt;CustomCache&gt;();
    caches.add(new CustomCache("testCache"));
    return caches;
}}
</code></pre>

<p>CustomCache</p>

<pre><code>public class CustomCache implements Cache {

private String name;
private final ConcurrentMap&lt;Object, Object&gt; map = new ConcurrentHashMap&lt;Object, Object&gt;();

public CustomCache(String name) {
    this.name = name;
}

@Override
public String getName() {
    return name;
}

@Override
public Object getNativeCache() {
    return null;
}

@Override
public ValueWrapper get(Object o) {
    System.out.println("In get of value wrapper cache");
    return new SimpleValueWrapper("fafa");
}

@Override
public &lt;T&gt; T get(Object o, Class&lt;T&gt; aClass) {
    System.out.println("In get of Custom Cache");
    this.get(o);
    return (T) "Test";
}

@Override
public void put(Object key, Object value) {
    System.out.println("Adding to cache");
    this.map.put(key, value);
}

@Override
public ValueWrapper putIfAbsent(Object o, Object o1) {
    System.out.println("Adding to Cache if Absent");
    return new SimpleValueWrapper("Test value from cache");
}

@Override
public void evict(Object o) {

}

@Override
public void clear() {

}}
</code></pre>

<p>Test Service Impl</p>

<pre><code>@Service("testService")
public class TestServiceImpl implements ITestService {

    @Cacheable(value = "testCache", key = "'key'")
    public String testMethod(String key) {
        System.out.println("In Test Method");
        return "fadfa";
    }}
</code></pre>