Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the best Cache practices in ehcache or spring cache for spring MVC?

Planning to implement cache mechanism for static data in spring web based application, can any one explain which is the best and how it works?

  • EhCache
  • Spring Cache
like image 223
Delli Kilari Avatar asked Sep 05 '16 15:09

Delli Kilari


People also ask

Is EhCache good?

EhCache is a widely used, pure Java cache that can be easily integrated with most popular Java frameworks, such as Spring and Hibernate. It is often considered to be the most convenient choice for Java applications since it can be integrated into projects easily.

What is the default cache in Spring boot?

Spring provides one concurrent hashmap as default cache, but we can override CacheManager to register external cache providers as well easily.

Which is a valid cache provider supported by Spring boot?

The Spring Boot framework allows the integration of various cache providers, such as EhCache, Redis, Hazelcast, Infinispan, Caffeine, etc.


1 Answers

Disclaimer : I am a Terracotta / Software AG employee, the maintainers of Ehcache

Ehcache is a JVM caching library, famous for being used as the default 2nd level cache for the Hibernate ORM

Spring cache was introduced in Spring 3.1, and brought annotations such as @CachePut to define uses of caches in a Spring application; by default Spring cache uses a plain Map, but you can configure it to use any popular caching framework, including Ehcache

Since Spring 4.1, Spring cache supports JSR-107, the standard for caching on the JVM.

What that means, is that you can add JSR-107 caching annotations, and then choose your caching library (ehcache 2 or 3 / guava / caffeine / etc.) : you're not tied to any caching vendor, even not tied to Spring cache annotations !

There's this nice blog post explaining the parallel between Spring cache annotations and JSR-107 annotations and if you choose to use Ehcache3 in your spring boot application, there's another interesting blog post explaining you how to integrate it in your app

like image 149
Anthony Dahanne Avatar answered Sep 28 '22 08:09

Anthony Dahanne