`
刘小小尘
  • 浏览: 62771 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

ehcache监听器的用法

 
阅读更多
EhCache event listener for preventing caching of null values in data store(ehcache监听器,坚挺value为null时清除)

ehcache的配置

<cache name="myNonNullCache"

<!-- cache configuration -->

>

<cacheEventListenerFactory class="com.example.cache.NotNullCacheEventListenerFactory" />

</cache>


监听工厂类
package com.pzoom.crabman.store;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-1 -7
 * Time: 上午10:33
 * 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) {
        return NotNullCacheEventListener.INSTANCE;
    }
}


监听实现类
package com.pzoom.crabman.store;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-1 -7
 * Time: 上午10:32
 * 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 NotNullCacheEventListener implements CacheEventListener {

    public static final CacheEventListener INSTANCE = new NotNullCacheEventListener();

    @Override
    public void notifyElementRemoved(final Ehcache cache, final Element element) throws CacheException {
    }

    @Override
    public void notifyElementPut(final Ehcache cache, final Element element) throws CacheException {
        removeIfNull(cache, element);
    }

    @Override
    public void notifyElementUpdated(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 notifyElementExpired(final Ehcache cache, final Element element) {
    }

    @Override
    public void notifyElementEvicted(final Ehcache cache, final Element element) {
    }

    @Override
    public void notifyRemoveAll(final Ehcache cache) {
    }

    @Override
    public void dispose() {
    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        throw new CloneNotSupportedException("Singleton instance");
    }
}













分享到:
评论

相关推荐

    EHCache API的基本用法

    EHCache API的基本用法 主要提供了一些EHCache简单的方法封装。

    ehcache监控工具ehcache-monitor-kit-1.0.3

    1.解压缩到目录下,复制ehcache-monitor-kit-1.0.0\lib\ehcache-probe-1.0.0.jar包到application的web-inf/lib目录下 2.将以下配置copy的ehcache.xml文件的ehcache标签中,注:上述链接中说的配置少写了个probe包名...

    hibernate+ehcache

    hibernate+ehcache hibernate+ehcache hibernate+ehcache hibernate+ehcache hibernate+ehcache

    ehcache开发工具包

    EhCache

    Ehcache 3(ehcache-3.8.1.jar)

    ehcache-3.8.1.jar

    ehcache-3.9.9-API文档-中英对照版.zip

    使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。 双语对照,边学技术、边学英语。

    ehcache-3.3.1-API文档-中文版.zip

    赠送jar包:ehcache-3.3.1.jar;...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。

    ehcache的配置参数详解

    hibernate ehcache.xml 配置详解

    spring+ehcache实例demo

    Ehcache是一种广泛使用的开源Java分布式缓存。主要面向通用缓存,Java EE和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个gzip缓存servlet过滤器,支持REST和SOAP api等特点。 Ehcache...

    spring3整合EhCache注解实例

    spring3整合EhCache注解实例

    ehcache-2.10.0-API文档-中文版.zip

    赠送jar包:ehcache-2.10.0.jar;...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。

    ehcache.jar及源码

    ehcache所需的ehcache-core-2.5.2.jar及其源码ehcache-core-2.5.2-sources.jar

    ehcache-core-2.6.11-API文档-中英对照版.zip

    使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。 双语对照,边学技术、边学英语。

    ehcache资料(包含ehcache jar包)

    ehcache资料(包含ehcache jar包)

    ehcache-2.10.0-API文档-中英对照版.zip

    使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。 双语对照,边学技术、边学英语。

    Ehcache分布式缓存与其在SpringBoot应用

    Ehcache 是一种广泛使用的开源 Java 分布式缓存。主要面向通用缓存,Java EE 和轻量级容器。它具有内存和磁盘存储,缓存加载器,缓存扩展,缓存异常处理程序,一个 gzip 缓存 servlet 过滤器,支持 REST 和 SOAP api...

    ehcache所需jar包

    ehcache所需jar包 cglib-nodep-2.2.jar ehcache-core-2.5.2.jar ehcache-spring-annotations-1.2.0.jar guava-13.0.1.jar ehcache-terracotta-2.5.2.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar terracotta-...

    Ehcache_Hello

    Ehcache 的一个简单demo案例 了解如何使用ehcache 以及掌握一些基本的api

    EHCache_技术文档

    EHCache_技术文档 EHCache缓存 spring缓存

    ehcache-web-2.0.4-API文档-中文版.zip

    赠送jar包:ehcache-web-2.0.4.jar;...使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持不变,注释和说明精准翻译,请放心使用。

Global site tag (gtag.js) - Google Analytics