Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/775566b33e59f7ffc325 to your computer and use it in GitHub Desktop.
Save abhirockzz/775566b33e59f7ffc325 to your computer and use it in GitHub Desktop.
Using JCache API
public class JCacheUsage{
public static void main(String[] args){
//bootstrap the JCache Provider
CachingProvider jcacheProvider = Caching.getCachingProvider();
CacheManager jcacheManager = jcacheProvider.getCacheManager();
//configure cache
MutableConfiguration<String, Integer> jcacheConfig = new MutableConfiguration<>();
jcacheConfig.setTypes(String.class, MyPreciousObject.class);
//create cache
Cache<String, MyPreciousObject> cache = jcacheManager.createCache("PreciousObjectCache", jcacheConfig);
//play around
String key = UUID.randomUUID().toString();
cache.put(key, new MyPreciousObject());
MyPreciousObject inserted = cache.get(key);
cache.remove(key);
cache.get(key); //will throw javax.cache.CacheException since the key does not exist
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment