Hazelcast确保成员上的预缓存接近加载

问题描述 投票:0回答:1

我有一个用例,在使用它之前,需要确保将数据加载到近缓存中。我正在使用Hazelcast作为缓存管理器提供程序。我确实以OBJECT内存格式将数据存储在近缓存中,并缓存本地条目。在应用程序启动时,我通过调用服务缓存方法来进行热缓存:

      @Override
      public void onApplicationEvent(final ApplicationReadyEvent applicationReadyEvent) {

       applicationReadyEvent.getApplicationContext().getBean(MyService.class).myCachedMethod(); //1 warm cahce

       applicationReadyEvent.getApplicationContext().getBean(MyService.class).myCachedMethod(); //2 warm near cache here

       MyData myData = applicationReadyEvent.getApplicationContext().getBean(MyService.class).myCachedMethod(); // 3 warm near cache here 
      //4
      //work with data from near cache here
        myDtata.doStufff();
      }

在此之后,我多次调用相同的方法,以将数据加载到近缓存中。问题是在我尝试使用方法数据时,有时未加载近缓存。看来Near Cache是​​异步加载的,并且在第4步我一直不从Near缓存接收数据。所以我的问题是-是否有任何方法可以使NearCache预加载,或确保在特定点填充NearCache?即使那意味着要等待一段时间才能填充它,然后再使用。添加Thread.sleep()对我来说很成功,但这绝不是可行的方法。 Hazelcast版本为3.11.4

感谢任何帮助。

spring-boot caching hazelcast near-cache
1个回答
0
投票

您可以使用<preloader>配置元素预加载Near缓存。请参阅以下与Reference Manual中的配置类似的示例示例:

<near-cache name="myDataStructure">
  <in-memory-format>OBJECT</in-memory-format>
  <preloader enabled="true"
             directory="nearcache-example"
             store-initial-delay-seconds="600"
             store-interval-seconds="600"/>
</near-cache>
© www.soinside.com 2019 - 2024. All rights reserved.