如何在启动期间在infinispan集群上创建缓存

时间:2018-05-17 18:45:46

标签: infinispan spring-cache

我使用

进行了以下配置
org.infinispan', name: 'infinispan-spring4-common', version: '9.1.7.Final'

问题是如何以编程方式创建缓存?或者如何在infinispan服务器启动期间创建缓存?

我无法创建标签'infinispan-as-spring-cache-provider'有人可以帮助我吗?

@Configuration
@Profile("infinispan-standalone")
@EnableCaching
public class InfinispanStandaloneConfig {

    private static final Logger logger = LoggerFactory.getLogger(InfinispanCacheConfiguration.class);

    @Autowired
    @Bean
    public RemoteCacheManager remoteCacheManager(@Value("${infinispan.remote.server-list}") String serverlist,
                                                 @Value("infinispan.admin.user") String user,
                                                 @Value("infinispan.admin.password") String pwd) {
        logger.info("inside the remote cache manager");

        Properties properties = new Properties();
        properties.setProperty("infinispan.client.hotrod.client_intelligence", "BASIC");
        properties.setProperty("infinispan.client.hotrod.marshaller", "org.infinispan.commons.marshall.jboss.GenericJBossMarshaller");

        RemoteCacheManager remoteCacheManager = new RemoteCacheManager(new ConfigurationBuilder().addServers(serverlist).withProperties(properties)
                .security().authentication().username(user).password(pwd)
                .build());
        remoteCacheManager.getCache("cart",true);
        return remoteCacheManager;
    }

    @Bean
    public SpringRemoteCacheManager cacheManager(RemoteCacheManager remoteCacheManager) {
        return new SpringRemoteCacheManager(remoteCacheManager);
    }
}

1 个答案:

答案 0 :(得分:1)

您需要使用Infinispan 9.2,您可以使用以下内容:

__mode

提供“template-name”是服务器上定义的配置模板。 或者,您也可以为缓存传递XML配置:

remoteCacheManager.administration().getOrCreateCache("cart", "template-name");