Usage of ehcache listeners

Source: Internet
Author: User

[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 ");}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.