Search code examples
cachingannotationsehcachespring-annotationsspring-cache

Difference between @CacheEvict and @TriggersRemove annotations


I want to use Ehcache in my portlet application. If I want to remove data from cache, it is better to use @CacheEvict or @TriggersRemove?

According to documentation it looks like @CacheEvict and @TriggersRemove annotations are very similar.


Solution

  • disclaimer: I am working on the Spring caching abstraction (amongst other things).

    These are two annotations from two different projects. I don't know much about TriggersRemove but from what I can see, it is ehcache specific.

    The caching abstraction in the Spring Framework is completely decoupled from the underlying infrastructure so you can use that with basically any caching library out there, including ehcache. If you want your code to be independent from the caching library you use, I'd advise not to use TriggersRemove. If that's not a problem for you, check the documentation of each solution and choose accordingly.