简体   繁体   English

infinispan 缓存可以在使用 hibernate 的同一 Spring Boot 应用程序的多个实例之间共享吗?

[英]Can the infinispan cache be shared among multiple instances of the same spring boot application using hibernate?

I have a spring boot application which uses hibernate.我有一个使用休眠的 Spring Boot 应用程序。 I want to run multiple instances of this application which connects to the same database.我想运行连接到同一个数据库的这个应用程序的多个实例。 I accidentally stumbled on infinispan as a second-level cache.我不小心偶然发现了 infinispan 作为二级缓存。 I would like to implement infinispan as a second-level cache for hibernate.我想实现 infinispan 作为休眠的二级缓存。 Now if I start multiple instances of this same spring boot application, will the infinispan caches of all the different instances be shared among each other?现在,如果我启动同一个 Spring Boot 应用程序的多个实例,所有不同实例的 infinispan 缓存是否会在彼此之间共享?

The default Infinispan configuration in use with Hibernate 2nd level cache would result on each instance trying to find each other. 与Hibernate 2级缓存一起使用的Infinispan默认配置将导致每个实例尝试相互查找。 For this to work, they'd need to find each other via UDP multicast, and then they would communicate with each other via TCP. 为此,他们需要通过UDP多播找到彼此,然后才能通过TCP相互通信。

We have an Spring Boot Hibernate Cache example that uses Infinispan that overrides this configuration for using it with a single instance. 我们有一个使用Infinispan的Spring Boot Hibernate Cache示例,该示例将覆盖此配置以用于单个实例。

If you comment this line , Infinispan would use the clustered configuration . 如果您对此发表评论,Infinispan将使用群集配置

The best way I've found to share cache between several machines using Spring Boot is using Redis. 我发现使用Spring Boot在多台计算机之间共享缓存的最好方法是使用Redis。

You just have to define the Redis server you are using, define the correct RedisTemplate in your configuration, and use the @Cacheable annotation which will store the result in Redis using the parameters you provided as a key. 您只需要定义要使用的Redis服务器,在配置中定义正确的RedisTemplate ,然后使用@Cacheable批注即可使用您提供的参数将结果存储在Redis中。 All instances will share the same cache source. 所有实例将共享相同的缓存源。

The issue comes if your Redis and different instances have a slow latency, this will cause the cache system to be slow and it might be more interesting to keep it the instance memory. 如果您的Redis和其他实例的延迟很慢,就会出现问题,这将导致缓存系统变慢,并且将其保留在实例内存中可能会更有趣。 However, it the severs are located closely enough to the Redis, it should be a great improvement and very helpful for scalability purposes reducing the pressure on the database :-) 但是,如果服务器位于与Redis足够近的位置,这应该是一个很大的改进,并且对于可伸缩性的目的非常有用,它可以减轻数据库的压力:-)

More info in this nice paper: https://medium.com/@MatthewFTech/spring-boot-cache-with-redis-56026f7da83a 这篇精美论文中的更多信息: https : //medium.com/@MatthewFTech/spring-boot-cache-with-redis-56026f7da83a

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

相关问题 使用Hibernate的Spring Boot应用程序如何与结构相同的多个表进行交互? - How can a Spring Boot Application using Hibernate interact with multiple tables, all structured identically? 如何维护同一应用程序的多个实例之间的消息顺序 - How to maintain order of messages among multiple instances of same application infinispan休眠缓存逐出 - infinispan hibernate cache eviction 带有多个数据库的Spring Boot / Hibernate应用程序问题 - Spring boot/ Hibernate application problems with multiple databases 二级缓存:Spring 3.2.2 + Hibernate 4.2.0 Infinispan - Second level cache: Spring 3.2.2 + Hibernate 4.2.0 Infinispan spring 集成以使用多个 spring boot 应用程序实例读取电子邮件 - spring integration to read emails with multiple instances of spring boot application infinispan:群集实例不共享缓存 - infinispan: clustred instances not sharing cache infinispan作为二级缓存休眠 - infinispan as second level cache hibernate 在分布式缓存l2上使用infinispan和hibernate进行连接锁定 - Connection lock using infinispan and hibernate on distributed cache l2 如何在Spring非EE应用程序中注入infinispan缓存? - How to Inject infinispan cache in a Spring non EE application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM