guavaはローカルキャッシュを実現します。

3390 ワード

private static  LoadingCache cache =
        //CacheBuilder         ,         newBuilder()   CacheBuilder   
        CacheBuilder.newBuilder()
                //       8,                 
                .concurrencyLevel(8)
                //      30    
                .expireAfterWrite(30, TimeUnit.MINUTES)
                //            10
                .initialCapacity(10)
                //         100,  100      LRU              
                .maximumSize(100)
                //           
                .recordStats()
                //         
                .removalListener(new RemovalListener() {
                 public  void onRemoval(RemovalNotification notification) {
                        System.out.println(notification+"was removed, cause is "+ notification.getCause());
                    }
                })
                //build       CacheLoader,         CacheLoader         
                .build(new CacheLoader() {
                            public String load(String str) throws Exception {
                                return str + " SPF";
                            };
                        }
)0
public static void main(String[] args) throws ExecutionException {
	String s = cache.get("Hi");
	System.out.println(s);
}