spring Redis 还是 Ehcache?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33123633/
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-09-08 00:49:14  来源:igfitidea点击:

Redis or Ehcache?

springcachingredisspring-bootehcache

提问by Sachin Sharma

Which is better suited for the following environment:

哪个更适合以下环境:

  1. Persistence not a compulsion.
  2. Multiple servers (with Ehcache some cache sync must be required).
  3. Infrequent writes and frequent reads.
  4. Relatively small database (very less memory requirement).
  1. 坚持不是强迫。
  2. 多个服务器(使用 Ehcache 必须需要一些缓存同步)。
  3. 不频繁的写入和频繁的读取。
  4. 相对较小的数据库(非常少的内存需求)。

I will pour out what's in my head currently. I may be wrong about these.

我会把我现在脑子里的东西倒出来。这些我可能是错的。

I know Redis requires a separate server (?) and Ehcache provides local cache so it must be faster but will replicate cache across servers (?). Updating all caches after some update on one is possible with Ehcache.

我知道 Redis 需要一个单独的服务器(?),而 Ehcache 提供本地缓存,所以它必须更快,但会跨服务器复制缓存(?)。使用 Ehcache 可以在对一个缓存进行一些更新后更新所有缓存。

My question is which will suit better for the environment I mentioned?
Whose performance will be better or what are scenarios when one may outperform another?

我的问题是哪个更适合我提到的环境?
谁的表现会更好,或者什么情况下可能会优于另一个?

Thanks in advance.

提前致谢。

回答by smallufo

You can think Redis as a shared data structure, while Ehcache is a memory blockstoring serialized data objects. This is the main difference.

你可以把Redis看作一个共享的数据结构,而Ehcache是​​一个存储序列化数据对象的内存块。这是主要的区别。

Redis as a shared data structuremeans you can put some predefineddata structure (such as String, List, Setetc) in one language and retrieve it in another language. This is useful if your project is multilingual, for example: Java the backend side , and PHP the front side. You can use Redis for a shared cache. But it can only store predefined data structure, you cannot insert any Java objects you want.

Redis 作为共享数据结构意味着您可以将一些预定义的数据结构(例如StringListSet)以一种语言放入并以另一种语言检索。如果您的项目是多语言的,这很有用,例如:Java 后端,PHP 前端。您可以将 Redis 用于共享缓存。但它只能存储预定义的数据结构,不能插入任何你想要的 Java 对象。

If your project is only Java, i.e. not multilingual, Ehcache is a convenient solution.

如果您的项目只有 Java,即不是多语言的,Ehcache 是一个方便的解决方案。

回答by Nikita Koksharov

You will meet issues with EhCache scaling and need resources to manage it during failover and etc. Redis benefitsover EhCache:

您将遇到 EhCache 扩展的问题,并需要资源在故障转移等期间对其进行管理。 Redis优于 EhCache:

  1. It uses time proven gossip protocol for Node discovery and synchronization.
  2. Availability of fully managed services like AWS ElastiCache, Azure Redis Cache. Such services offers full automation, support and management of Redis, so developers can focus on their applications and not maintaining their databases.
  3. Correct large memory amount handling (we all know that Redis can manage with hundreds of gigabytes of RAM on single machine). It doesn't have problems with Garbage collection like Java.
  1. 它使用经过时间验证的八卦协议进行节点发现和同步。
  2. AWS ElastiCacheAzure Redis 缓存等完全托管服务的可用性。此类服务提供 Redis 的完全自动化、支持和管理,因此开发人员可以专注于他们的应用程序,而不是维护他们的数据库。
  3. 正确处理大内存量(我们都知道 Redis 可以在单机上管理数百 GB 的 RAM)。它没有像 Java 那样的垃圾收集问题。

And finally existence of Java Developer friendly Redis client - Redisson.
Redisson provides many Java friendly objects on top of Redis, like:

最终存在对 Java 开发人员友好的 Redis 客户端 - Redisson
Redisson在 Redis之上提供了许多对 Java 友好的对象,例如:

  • Set
  • ConcurrentMap
  • List
  • Queue
  • Deque
  • BlockingQueue
  • BlockingDeque
  • ReadWriteLock
  • Semaphore
  • Lock
  • AtomicLong
  • CountDownLatch
  • Publish / Subscribe
  • ExecutorService
  • and many more...
  • 并发映射
  • 列表
  • 队列
  • 德克
  • 阻塞队列
  • 阻塞队列
  • 读写锁
  • 信号
  • 原子长
  • 倒计时锁存器
  • 发布/订阅
  • 执行者服务
  • 还有很多...

Redisson supports local cachefor Map structure which cold give you 45xperformance boost for read operations.

Redisson 支持Map 结构的本地缓存,它可以为您提供45 倍的读取操作性能提升。

Here is the articledescribing experience of Personal Capital company of transition from EhCache to Redis

这里是描述Personal Capital公司从EhCache过渡到Redis的经验的文章