是否可以使用Infinispan作为阻塞缓存?

时间:2022-01-26 04:47:05

In our project we are using Infinispan and Spring's @Cacheable annotation, mainly for caching I/O results.

在我们的项目中,我们使用Infinispan和Spring的@Cacheable注释,主要用于缓存I / O结果。

As we have many concurrent calls, we would like to avoid 2 threads performing the same data retrieval twice, hence having the second @Cacheable method call (with the same cache key) blocked until the first one finishes and returns a result.

由于我们有许多并发调用,我们希望避免2个线程执行两次相同的数据检索,因此第二个@Cacheable方法调用(具有相同的缓存键)被阻塞,直到第一个完成并返回结果。

I am used to Ehcache's SelfPopulatingCache which supports this automatically, but is there a similar feature in Infinispan?

我习惯了Ehcache的SelfPopulatingCache,它自动支持这个,但在Infinispan中有类似的功能吗?

Ideally this should be used via Spring's @Cacheable so that we avoid boilerplate code. I have noticed that Spring 4.3 now has @Cacheable.sync() but it is indicated that it is only a hint and it depends on the underlying cache provider implementation. Also, we are not on Spring 4.3 yet so a solution for 4.2 would be better.

理想情况下,这应该通过Spring的@Cacheable使用,以便我们避免使用样板代码。我注意到Spring 4.3现在有@ Cacheable.sync(),但它表明它只是一个提示,它取决于底层缓存提供程序实现。另外,我们还没有使用Spring 4.3,所以4.2的解决方案会更好。

1 个解决方案

#1


2  

If you want that feature out-of-the-box you'll have to upgrade to 4.3. If you are using 4.2, upgrading to 4.3 should be painless anyway (if that's not the case, let us know!)

如果您希望该功能开箱即用,则必须升级到4.3。如果您使用4.2,升级到4.3应该是无痛的(如果不是这样,请告诉我们!)

As Ben already mentioned, you can use the JCache bridge that has explicit support for such a call (i.e. it will work for any JSR-107 compliant cache library). Infinispan does not have such native feature yet, I've just submitted a feature request in their tracker.

正如Ben已经提到的,您可以使用明确支持此类调用的JCache桥(即它适用于任何符合JSR-107的缓存库)。 Infinispan还没有这样的原生功能,我刚刚在他们的追踪器中提交了一个功能请求。

#1


2  

If you want that feature out-of-the-box you'll have to upgrade to 4.3. If you are using 4.2, upgrading to 4.3 should be painless anyway (if that's not the case, let us know!)

如果您希望该功能开箱即用,则必须升级到4.3。如果您使用4.2,升级到4.3应该是无痛的(如果不是这样,请告诉我们!)

As Ben already mentioned, you can use the JCache bridge that has explicit support for such a call (i.e. it will work for any JSR-107 compliant cache library). Infinispan does not have such native feature yet, I've just submitted a feature request in their tracker.

正如Ben已经提到的,您可以使用明确支持此类调用的JCache桥(即它适用于任何符合JSR-107的缓存库)。 Infinispan还没有这样的原生功能,我刚刚在他们的追踪器中提交了一个功能请求。