[Java] EhCache event listener for preventing caching of null values in data store (ehcache listener, clear when strong value is null) [java] [java] ehcache configuration <cache name = "myNonNullCache" <! -- Cache configuration --> <cacheEventListenerFactory class = "com. example. cache. notNullCacheEventListenerFactory "/> </cache> listens to the factory package com. pzoom. crabman. store;/*** Created with IntelliJ IDEA. * User: Administrator * Date: 13-1-7 * Time: am * To change this template use File | Settings | File Templates. */import java. util. properties; import net. sf. ehcache. event. cacheEventListener; import net. sf. ehcache. event. cacheEventListenerFactory; public class NotNullCacheEventListenerFactory extends CacheEventListenerFactory {@ Override public CacheEventListener createCacheEventListener (final Properties properties Properties) {return NotNullCacheEventListener. INSTANCE ;}} listener implementation class package com. pzoom. crabman. store;/*** Created with IntelliJ IDEA. * User: Administrator * Date: 13-1-7 * Time: am * To change this template use File | Settings | File Templates. */import net. sf. ehcache. cacheException; import net. sf. ehcache. ehcache; import net. sf. ehcache. element; import net. sf. ehcache. event. cacheEventListener; public class implements CacheEventListener {public static final CacheEventListener INSTANCE = new NotNullCacheEventListener (); @ Override public void implements yelementremoved (final Ehcache cache, final Element element) throws CacheException {}@ Override public void incluyelementput (final Ehcache cache, final Element element) throws CacheException {removeIfNull (cache, element);} @ Override public void incluyelementupdated (final Ehcache cache, final Element element) throws CacheException {removeIfNull (cache, element);} private void removeIfNull (final Ehcache cache, final Element element) {if (element. getObjectValue () = null) {cache. remove (element. getKey () ;}@ Override public void incluyelementexpired (final Ehcache cache, final Element element) {}@ Override public void incluyelementevicted (final Ehcache cache, final Element element) {}@ Override public void policyremoveall (final Ehcache cache) {}@ Override public void dispose () {}@ Override public Object clone () throws CloneNotSupportedException {throw new CloneNotSupportedException ("Singleton instance ");}}