Returns an instance of the memcache, or null if we can't get at it. - Java javax.cache

Java examples for javax.cache:Cache

Description

Returns an instance of the memcache, or null if we can't get at it.

Demo Code


import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheFactory;
import javax.cache.CacheManager;

public class Main{
    public static void main(String[] argv) throws Exception{
        System.out.println(getCache());
    }/* w  w  w  .  ja  v  a 2 s  . c o m*/
    /**
     * Returns an instance of the memcache, or null if we can't get at it.
     * @return cache
     */
    public static Cache getCache() {
        Cache cache;
        try {
            CacheFactory cf = CacheManager.getInstance().getCacheFactory();
            cache = cf.createCache(Collections.emptyMap());
        } catch (CacheException e) {
            cache = null;
        }
        return cache;
    }
}

Related Tutorials