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

偶尔善良 提交于 2019-12-13 11:53:56

问题


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

回答1:


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




回答2:


Ehcache3 has support for JSR 107

For Ehcache2 may be you can use this implementation

https://github.com/ehcache/ehcache-jcache/tree/master/ehcache-jcache



来源:https://stackoverflow.com/questions/39334043/what-are-the-best-cache-practices-in-ehcache-or-spring-cache-for-spring-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!