Wednesday, March 9, 2016

Hazle cast cache usage in wso2 products

Hazle cast cache usage in wso2 products:

Imports:

import javax.cache.Cache;

import javax.cache.CacheConfiguration;

import javax.cache.CacheManager;

import javax.cache.Caching;

Code:


private void playWithCache()

{

final CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager("test");

final String cacheName = "cacheXXX";

final Cache<String, Integer> cache = cacheManager.<String,Integer>getCache(cacheName) == null ? cacheManager.<String,Integer>createCacheBuilder(cacheName).setExpiry(CacheConfiguration.ExpiryType.MODIFIED, new CacheConfiguration.Duration(TimeUnit.MINUTES, 10)).setStoreByValue(false).build() : cacheManager.<String,Integer>getCache(cacheName);

final intvalue = 9876;

final String key = "key-1";



logger.info("Getting cache entry from cache: "+cache.get(key));

logger.info("Inserting cache entry into cache..");

cache.put(key, value);

logger.info("Inserting cache entry into cache done.");

logger.info("Getting cache entry from cache after insertion: "+cache.get(key));

}

No comments:

Post a Comment