create Read Cache - Java javax.cache

Java examples for javax.cache:Cache

Description

create Read Cache

Demo Code

// Copyright (C) YOYO Project Team. All rights reserved.
import javax.cache.Cache;
import javax.cache.CacheBuilder;
import javax.cache.CacheManager;
import javax.cache.Caching;
import javax.cache.transaction.IsolationLevel;
import javax.cache.transaction.Mode;

public class Main{
    public static void main(String[] argv) throws Exception{
        String cacheName = "java2s.com";
        System.out.println(createReadCache(cacheName));
    }//  www  .  j  av  a  2  s .  c  o  m
    
    private static final CacheManager MANAGER = Caching.getCacheManager();
    
    public static <K, V> Cache<K, V> createReadCache(final String cacheName) {
        final CacheBuilder<K, V> builder = MANAGER
                .createCacheBuilder(cacheName);
        builder.setStatisticsEnabled(true);
        builder.setReadThrough(true);
        builder.setWriteThrough(false);
        builder.setTransactionEnabled(IsolationLevel.READ_COMMITTED,
                Mode.LOCAL);
        return builder.build();
    }
}

Related Tutorials