0

Hibernate (and so JPA which is wrapper on hibernate) provides two levels of caching mechanisms. a) level 1 cache which is at session object layer/level b) level 2 cache which is at session factory layer/level

If I am using external caches like redis or ehcache, where does this cache sit in the above. Or should I disable level 2 cache to enable redis/ehcache. Not sure how and where the external cache fits with level 1 & 2 caches.

Or - Are various configurations possible?

Could someone explain. Thanks in advance.

1 Answers1

0

Level 1 cache is considered a local in-memory cache, it can be a local Redis/Memcache cache as well. The 2nd level cache is like a proxy server that caches the results of a query and all subsequeuent queries from any server will provide the result from the cache if it's available.

Level 1 cache result is only available to one server, where as Level 2 cache can be considered as a distributed cache that's available to all servers. If your application is running on only one server/instance than it does not make sense to use Level 2 cache.

You can consider using proxy server as well for your database for example if you're using MySQL than you can consider using ProxySQL, mysql-proxy etc.

sonus21
  • 5,178
  • 2
  • 23
  • 48
  • thanks for your respone - a similar Q if it interests you. [What is the default cache strategy when using Redis with spring or spring boot?](https://stackoverflow.com/questions/63976247/what-is-the-default-cache-strategy-when-using-redis-with-spring-or-spring-boot) –  Sep 20 '20 at 06:57
  • If you find these answers helpful, please accept them. – sonus21 Sep 20 '20 at 15:40