简体   繁体   English

Infinispan 缓存放置不在循环中工作

[英]Infinispan cache put is not working in loop

I am using embedded cachemanager and i am trying to put entries in cache in for loop but when the next request is fired i am seeing cache empty.我正在使用嵌入式缓存管理器,并且我正在尝试将条目放入 for 循环中的缓存中,但是当下一个请求被触发时,我看到缓存为空。 Below is my implementation -下面是我的实现 -

EmbeddedCacheManager manager=null;
    {
        try {
            manager = new DefaultCacheManager("src/main/resources/infinispan.xml");


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    Cache cache=manager.getCache();



for (JsonElement jsonElement : jsonArray)
            {
                 id=jsonElement.getAsJsonObject().get("_id").getAsString();
                  id1= id.replace("-","");
                JsonObject source = jsonElement.getAsJsonObject().getAsJsonObject("_src");
                String jsonString = source.toString();


                Dummy dummy = new Gson().fromJson(jsonString, Dummy.class);



                if(cache.get(id1)!=null){
                    retVal.add((Dummy) cache.get(id1));
                    System.out.println("This is cached !");
                }else {
                    cache.put(id1,dummy);
                    retVal.add(dummy);
                    System.out.println("This is not cached");
                }

            }

Add infinispan-bom to your pom.xml file before the starter dependencies, as follows:将 infinispan-bom 添加到您的 pom.xml 文件中,在启动器依赖项之前,如下所示:

<dependencyManagement>
    <dependencies>
       <dependency>
           <groupId>org.infinispan</groupId>
           <artifactId>infinispan-bom</artifactId>
           <version>${version.infinispan}</version>
           <type>pom</type>
           <scope>import</scope>
       </dependency>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>${version.spring.boot}</version>
           <type>pom</type>
           <scope>import</scope>
       </dependency>
       <dependency>
           <groupId>org.infinispan</groupId>
           <artifactId>infinispan-spring-boot-starter</artifactId>
           <version>${version.infinispan.starter}</version>
       </dependency>
    </dependencies>
 </dependencyManagement>
<dependency>
  <groupId>org.infinispan</groupId>
  <artifactId>infinispan-spring-boot-starter-embedded</artifactId>
  <version>${version.infinispan.starter}</version>
</dependency>

your bean should have你的豆子应该有

private final EmbeddedCacheManager cacheManager;

@Autowired
public YourBean(EmbeddedCacheManager cacheManager) {
    this.cacheManager = cacheManager;
}

if you need to customize EmbeddedCacheManager do如果你需要自定义EmbeddedCacheManager

@Bean
public InfinispanCacheConfigurer cacheConfigurer() {
    return manager -> {
        final Configuration ispnConfig = new ConfigurationBuilder()
                        .clustering()
                        .cacheMode(CacheMode.LOCAL)
                        .build();

        manager.defineConfiguration("local-sync-config", ispnConfig);
    };
}

You will find good examples at https://infinispan.org/infinispan-spring-boot/master/spring_boot_starter.html你会在https://infinispan.org/infinispan-spring-boot/master/spring_boot_starter.html找到很好的例子

暂无
暂无

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

相关问题 Infinispan - 没有删除缓存的选项吗? - Infinispan - is there no option to delete a cache? Spring Session 的推荐 Infinispan 缓存模式 - Recommended Infinispan cache mode for Spring Session Infinispan + Spring 启动 - 不缓存 - Infinispan + Spring Boot - Doesn't Cache ISPN000217 同时将数据添加到 infinispan 缓存 - ISPN000217 while adding data to infinispan cache springboot + infinispan 失效模式:如何与共享缓存存储一起使用? - springboot + infinispan invalidation mode : How can used with shared cache storage? Spring 引导应用程序的 Hibernate 缓存(Infinispan,Hazelcast,理想可扩展) - Hibernate Cache for Spring Boot Application (Infinispan, Hazelcast, ideally scalable) 使用@Cacheable Spring批注并手动添加到Infinispan Cache - Using @Cacheable Spring annotation and manually add to Infinispan Cache Infinispan 集群 REPL_ASYNC 缓存:命令在两个节点之间无限期弹跳 - Infinispan clustered REPL_ASYNC cache: command indefinitely bounced between two nodes infinispan 缓存可以在使用 hibernate 的同一 Spring Boot 应用程序的多个实例之间共享吗? - Can the infinispan cache be shared among multiple instances of the same spring boot application using hibernate? Spring Cache中的@Cacheable将值存储在cache外部的redis中。 如何将它放入Redis的缓存中? - @Cacheable in Spring Cache Stores value in redis outside cache . How do i put it inside cache in redis?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM