Created
July 18, 2012 13:43
-
-
Save jlandure/3136285 to your computer and use it in GitHub Desktop.
TestPerfJCache.java
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
import java.util.concurrent.TimeUnit; | |
import javax.cache.Cache; | |
import javax.cache.CacheConfiguration.Duration; | |
import javax.cache.CacheConfiguration.ExpiryType; | |
import javax.cache.CacheException; | |
import javax.cache.Caching; | |
import org.perf4j.StopWatch; | |
public class TestPerfJCache { | |
public static final String KEY = "KEY"; | |
public static final String VALUE = "VALUE"; | |
public static void main(String[] args) throws CacheException { | |
StopWatch stopWatch = new StopWatch(); | |
Cache<String, String> maps = Caching.getCacheManager().<String, String> createCacheBuilder("foo")// | |
.setExpiry(ExpiryType.ACCESSED, new Duration(TimeUnit.DAYS, 10))// | |
// .setStoreByValue(false)// | |
.build(); | |
for (int i = 0; i < 1_000_000; i++) { | |
String key = KEY + i; | |
String value = VALUE + i; | |
System.out.println("get Object in memory :" + maps.get(key)); | |
// set a new object | |
maps.put(key, value); | |
System.out.println("set Object in memory :"); | |
System.out.println("Get Object after set :" + maps.get(key)); | |
if (maps.get("KEY0") == null) { | |
System.out.println("STOPPING : no more object in cache!"); | |
return; | |
} | |
} | |
stopWatch.stop(); | |
System.out.println("OldFashion Elapsed Time: " + stopWatch.getElapsedTime()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment