java spring MVC 的 ehcache 或 spring 缓存中的最佳缓存实践是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39334043/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:17:09  来源:igfitidea点击:

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

javaspringspring-mvcehcachespring-cache

提问by Delli Kilari

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?

计划在基于 Spring Web 的应用程序中实现静态数据的缓存机制,有人能解释一下哪个是最好的以及它是如何工作的吗?

  • EhCache
  • Spring Cache
  • 缓存
  • 弹簧缓存

回答by Anthony Dahanne

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

免责声明:我是Terracotta / Software AG 的员工,Ehcache 的维护者

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

Ehcache是一个 JVM 缓存库,以用作 Hibernate ORM 的默认二级缓存而闻名

Spring cachewas introduced in Spring 3.1, and brought annotations such as @CachePutto 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

Spring 缓存是在 Spring 3.1 中引入的,并带来了诸如@CachePut定义 Spring 应用程序中缓存使用的注解;默认情况下,Spring 缓存使用普通 Map,但您可以将其配置为使用任何流行的缓存框架,包括 Ehcache

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

从 Spring 4.1 开始,Spring 缓存支持JSR-107,这是在 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 !

这意味着,您可以添加 JSR-107 缓存注释,然后选择您的缓存库(ehcache 2 或 3/ guava/ caffeine/):您没有绑定到任何缓存供应商,甚至没有绑定到 Spring缓存注释!

There's this nice blog post explaining the parallel between Spring cache annotations and JSR-107 annotationsand 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

一篇很好的博客文章解释了 Spring 缓存注释和 JSR-107 注释之间的相似之处,如果您选择在 Spring Boot 应用程序中使用 Ehcache3,还有另一篇有趣的博客文章解释了如何将它集成到您​​的应用程序中

回答by Kalpesh Soni

Ehcache3 has support for JSR 107

Ehcache3 支持 JSR 107

For Ehcache2 may be you can use this implementation

对于 Ehcache2 可能是你可以使用这个实现

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

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