Automatic cache invalidation in Spring
<p>I have a class that performs some read operations from a service XXX. These read operations will eventually perform DB reads and I want to optimize on those calls by caching the results of each method in the class for a specified custom key per method.</p>

<pre><code>Class a {

    public Output1 func1(Arguments1 ...) {
    ...
    }

    public Output2 func2(Arguments2 ...) {
    ...
    }

    public Output3 func3(Arguments3 ...) {
    ...
    }

    public Output4 func4(Arguments4 ...) {
    ...
    }
}
</code></pre>

<p>I am thinking of using Spring <code>caching(@Cacheable annotation)</code> for caching results of each of these methods. </p>

<p>However, I want cache invalidation to happen automatically by some mechanism(ttl etc). Is that possible in Spring caching ? I understand that we have a <code>@CacheEvict</code> annotation but I want that eviction to happen automatically.</p>

<p>Any help would be appreciated.</p>