Infinispan distributed cache mode with K8

18 Views Asked by At

i am using infinispan cache to communicate multiple services deployed in K8. i want these caches to be

  1. replicated, to only a few services (not all) just so that when a service dies, it should be able to recover its caches from another service when it restarts)
  2. accessible for read/write/evict in specific services.

below is the cache configuration i am using, this configuration is shared in all services using common library.

@PostConstruct
    public void init(){
        if(defaultCacheManager==null){
            defaultCacheManager = cacheManager();
        }
        for(String cacheName:cacheNames){
            createCache(defaultCacheManager,cacheName);
        }
    }

public Cache<String, String> createCache(DefaultCacheManager cacheManager, String cacheName) {
        return this.buildCache(cacheName, cacheManager, cacheExpiringEvictingConfig(cacheManager));
    }

    private Configuration cacheExpiringEvictingConfig(DefaultCacheManager cacheManager) {
        ConfigurationBuilder confBuilder = new ConfigurationBuilder();
        confBuilder.expiration().lifespan(200, TimeUnit.HOURS);
        confBuilder.memory().maxCount(1000000).whenFull(EvictionStrategy.REMOVE);
        confBuilder.clustering().cacheMode(CacheMode.DIST_ASYNC);
        return confBuilder.build();
    }

 private <K, V> Cache<K, V> buildCache(String cacheName, DefaultCacheManager cacheManager, Configuration configuration) {
        cacheManager.defineConfiguration(cacheName, configuration);
        Cache<K, V> cache = cacheManager.getCache(cacheName);
        return cache;
    }

i'd appreciate if someone can go through this and give me a better configuration which can provide optimal performance (faster read/writes) as my services are heavily relying on caches. also i can see distributed working fine in my local machine with single jvm, but when deployed in k8. caches are not synced.

0

There are 0 best solutions below