创建一个CacheManager
CacheManager cacheManager = Caching.getCacheManager();
它返回一个default 单例CacheManager。
CacheManagers can have names and classloaders configured in. e.g.
CacheManager cacheManager =
Caching.getCacheManager("app1", Thread.currentThread().getContextClassLoader());
Implementations may also support direct creation with new for maximum flexibility:
CacheManager cacheManager =
new RICacheManager("app1", Thread.currentThread().getContextClassLoader());
CacheManager可以通过下面的方式来配置名称和classloader:
CacheManager cacheManager =
new RICacheManager("app1", Thread.currentThread().getContextClassLoader());
创建缓存
cacheManager = getCacheManager();
CacheConfiguration cacheConfiguration = cacheManager.createCacheConfiguration();
cacheConfiguration.setReadThrough(true);
Cache testCache = cacheManager.createCacheBuilder("testCache")
.setCacheConfiguration(cacheConfiguration).build();
获取缓存引用
Cache<Integer, Date> cache = cacheManager.getCache("testCache");
基本缓存操作
把数据存入缓存
Cache<Integer, Date> cache = cacheManager.getCache(cacheName);
Date value1 = new Date();
Integer key = 1;
cache.put(key, value1);
从缓存中获取数据
Cache<Integer, Date> cache =
cacheManager.getCache(cacheName);
Date value2 = cache.get(key);
从缓存中删除
Cache<Integer, Date> cache =
cacheManager.getCache(cacheName);
Integer key = 1;
cache.remove(key);
最后欢迎大家访问我的个人网站:1024s