简体   繁体   English

哪个缓存管理器/缓存库用于 Spring 和 EHCache 3?

[英]Which Cache Manager/Cache library to use for Spring and EHCache 3?

Integrating EhCache3 cache provider for spring boot app.为 Spring Boot 应用程序集成 EhCache3 缓存提供程序。 I need to decide which cache manager to use.我需要决定使用哪个缓存管理器。 Ideally I want to use Springs caching annotations on my caching methods such as @Cacheable instead of the jsr (@CacheResult) but for cachemanager/cache libraries I cant decide on the below理想情况下,我想在我的缓存方法上使用 Springs 缓存注释,例如 @Cacheable 而不是 jsr (@CacheResult) 但对于缓存管理器/缓存库,我无法决定以下内容

Cache library annotations Im deciding on with ehcache3 provider :缓存库注释我决定使用 ehcache3 提供程序:

javax爪哇 ehcache ehcache spring春天 Jcache?(which I thought was jsr/javax) Jcache?(我认为是 jsr/javax)
javax.cache.Cache javax.cache.Cache org.ehcache.Cache org.ehcache.Cache org.springframework.cache.Cache org.springframework.cache.Cache org.springframework.cache.Cache org.springframework.cache.Cache
javax.cache.Cache.CacheManager javax.cache.Cache.CacheManager org.ehcache.CacheManager org.ehcache.CacheManager org.springframework.cache.CacheManager org.springframework.cache.CacheManager org.springframework.cache.jcache.JCacheCacheManager org.springframework.cache.jcache.JCacheCacheManager

Any suggestions on which implementation?关于哪个实施的任何建议? Maybe I am not to clear on what differentiates the above implementations and when to choose one over the other也许我不清楚上述实现的区别以及何时选择一个而不是另一个

ehcache is pretty old and well known caching library. ehcache 是一个非常古老且众所周知的缓存库。 Its also the default 2nd level cache in Hibernate.它也是 Hibernate 中默认的二级缓存。 I have used ehcache in many many applications without any issues , so I would go with ehcache.我在许多应用程序中都使用了 ehcache,没有任何问题,所以我会选择 ehcache。

The short answer:简短的回答:

EHCache3 does not have an extra Spring integration but is integrated via the general Java caching API JCache/JSR107 integration. EHCache3 没有额外的 Spring 集成,而是通过通用 Java 缓存 API JCache/JSR107 集成进行集成。 The relevant official documentation can be found at: https://docs.spring.io/spring-framework/docs/5.3.x/reference/html/integration.html#cache-store-configuration-ehcache相关官方文档可见: https ://docs.spring.io/spring-framework/docs/5.3.x/reference/html/integration.html#cache-store-configuration-ehcache

Longer answer:更长的答案:

The options you present are not real options but different concepts.你提出的选项不是真正的选项,而是不同的概念。 I try to explain it briefly:我试着简单解释一下:

  • javax.cache.Cache : This is the interface that a JSR107 compliant cache implements. javax.cache.Cache :这是符合 JSR107 的缓存实现的接口。 EHCache3 also provides an implementation of this interface. EHCache3 也提供了这个接口的实现。
  • org.ehcache.Cache : That is the native interface of a EHCache3 cache that may have different functions not supported by the JSR107 Cache interface. org.ehcache.Cache :这是 EHCache3 缓存的本机接口,可能具有 JSR107 Cache接口不支持的不同功能。 If only standard Spring is used in your application, except for the configuration which needs to decide which cache cache implementation to use, you will not get in contact with this interface.如果你的应用中只使用标准的 Spring,除了需要决定使用哪个缓存缓存实现的配置,你不会接触到这个接口。
  • org.springframework.cache.Cache : That is the interface of the abstracted Spring cache. org.springframework.cache.Cache :即抽象的 Spring 缓存的接口。 It only has a very small subset of cache operations that are needed for Spring.它只有 Spring 所需的缓存操作的一小部分。 The Spring Caching is always using this interface. Spring Caching 总是使用这个接口。
  • org.springframework.cache.jcache.JCacheCacheManager : That is an implementation of org.springframework.cache.CacheManager usable JCache compliant caches. org.springframework.cache.jcache.JCacheCacheManager :这是org.springframework.cache.CacheManager可用 JCache 兼容缓存的实现。 That will be used with EHCache3 as well since EHCache3 is integrated via JSR107.这也将与 EHCache3 一起使用,因为 EHCache3 是通过 JSR107 集成的。

So when using a JSR107 compliant cache there are two API translations: The Spring cache implementation translates to a JSR107 cache and than the JSR107 cache implementation translates to the native cache API.因此,当使用符合 JSR107 的缓存时,有两种 API 转换:Spring 缓存实现转换为 JSR107 缓存,而 JSR107 缓存实现转换为本地缓存 API。

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

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