Created
January 26, 2013 12:23
-
-
Save richmidwinter/4642026 to your computer and use it in GitHub Desktop.
JSR-107 example.
This file contains hidden or 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
package javax.cache; | |
import org.junit.Test; | |
import java.util.concurrent.TimeUnit; | |
import static junit.framework.Assert.assertEquals; | |
import static junit.framework.Assert.assertNull; | |
/** | |
* @author Greg Luck | |
*/ | |
public class CacheTest { | |
@Test | |
public void simpleAPI() { | |
String cacheName = "sampleCache"; | |
CacheManager cacheManager = Caching.getCacheManager(); | |
SimpleConfiguration<String, Integer> config = new SimpleConfiguration<String, Integer>(); | |
config.setStoreByValue(false) | |
.setExpiryPolicy(new ExpiryPolicy.Accessed<String, Integer>(new Configuration.Duration(TimeUnit.HOURS, 1))) | |
.setStatisticsEnabled(true); | |
Cache<String, Integer> cache = cacheManager.configureCache(cacheName, config); | |
String key = "key"; | |
Integer value1 = 1; | |
cache.put(key, value1); | |
Integer value2 = cache.get(key); | |
assertEquals(value1, value2); | |
cache.remove("key"); | |
assertNull(cache.get("key")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment