简体   繁体   English

对于Spring MVC,ehcache或spring缓存中的最佳缓存实践是什么?

[英]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? 计划在基于Spring Web的应用程序中为静态数据实现缓存机制,有谁能解释哪个是最好的,以及它如何工作?

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

Disclaimer : I am a Terracotta / Software AG employee, the maintainers of Ehcache 免责声明:我是Terracotta / Software AG的雇员,Ehcache的维护者

Ehcache is a JVM caching library, famous for being used as the default 2nd level cache for the Hibernate ORM Ehcache是一个JVM缓存库,以被用作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; Spring缓存是在Spring 3.1中引入的,并引入了诸如@CachePut注释来定义Spring应用程序中缓存的使用。 by default Spring cache uses a plain Map, but you can configure it to use any popular caching framework, including Ehcache 默认情况下,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 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 这篇不错的博客文章解释了Spring缓存注释和JSR-107注释之间的相似之处 ,如果您选择在Spring Boot应用程序中使用Ehcache3, 那么还有另一篇有趣的博客文章解释了如何将其集成到您的应用程序中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM