Last active
August 29, 2015 14:15
-
-
Save abhirockzz/775566b33e59f7ffc325 to your computer and use it in GitHub Desktop.
Using JCache API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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