Using Ehcache SampledCache

SampledCache is an implementation of CachedMBean and exposes Cache Statistics. It’s a Cache decorator for getting statistics for a Cache. It’s fairly simple to use, let see a quick sample The complete code can be found at EhcacheStatsDemo.java public static void ehCacheStatsDemo() throws NotCompliantMBeanException { CacheManager cacheManager = CacheManager.newInstance(); Ehcache cache = cacheManager.addCacheIfAbsent("testCache"); SampledCache sampledCache […]

Continue reading


Getting Started with Ehcache

Ehcache is a widely used caching system in Java world. Have been seeing requests for a simple getting started tutorial for the Ehcache. Ehcache is fairly simple to use. Pre-requisites Java 6+ If it’s a maven project, add the following entry in your pom.xml <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>2.9.0</version> </dependency> If it’s simple Java project in […]

Continue reading


[Java Tips] Printing java.util.Map contents

Printing java.util.Map contents is quite a common use case. Most of the time end implementing the same logic of using iterator and writing to Console. Let’s explore a simpler way and taste goodness of Google Guava. Code can be found at MapPrinter.java public static void printMapOnConcole(Map map) { Preconditions.checkNotNull(map); Joiner.MapJoiner mapJoiner = Joiner.on("\n").withKeyValueSeparator("="); System.out.println(mapJoiner.join(map)); } […]

Continue reading