package org.frame.ehcache;
import java.lang.reflect.Method;
import java.util.List;
import net.sf.ehcache.Cache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
/**
* @Description : 描述
* @author liuq
*/
public class MethodCacheAfterAdvice implements AfterReturningAdvice,InitializingBean {
	
	private static final Log logger = LogFactory.getLog(MethodCacheAfterAdvice.class);
	private Cache cache;
	public void setCache(Cache cache) {
		this.cache = cache;
	}
	public MethodCacheAfterAdvice() {
		super();
	}
	@SuppressWarnings({ "unchecked"})
	public void afterReturning(Object arg0, Method arg1, Object[] arg2,Object arg3) throws Throwable {
		String className = arg3.getClass().getName();
		List list = cache.getKeys();
		for (int i = 0; i < list.size(); i++){
			String cacheKey = String.valueOf(list.get(i));
			if (cacheKey.startsWith(className)) {
				cache.remove(cacheKey);
				logger.debug("remove cache " + cacheKey);
			}
		}
	}
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(cache,"Need a cache. Please use setCache(Cache) create it.");
	}
}
 最近下载更多
最近下载更多
                
                kong.yee     LV40
                2020年7月5日
            
            
        
                adolph_jiang     LV11
                2020年4月28日
            
            
        
                gwt爱学习     LV16
                2019年5月30日
            
            
        
                faith帅军     LV7
                2019年5月12日
            
            
        
                1812215714     LV8
                2019年4月29日
            
            
        
                itlaolang     LV6
                2019年1月18日
            
            
        
                adminmwx     LV20
                2018年12月27日
            
            
        
                夕四呀     LV6
                2018年12月20日
            
            
        
                我一直在笑     LV10
                2018年10月12日
            
            
        
                pakadp     LV4
                2018年5月17日
            
            
         最近浏览更多
最近浏览更多
                
                iiiiiiixiiiiii     LV1
                2023年12月31日
            
            
        
                Weishenghui     LV7
                2023年10月20日
            
            
        
                he2yong     LV11
                2022年7月18日
            
            
        
                qujianbo     LV1
                2022年4月27日
            
            
        
                isfrand     LV4
                2022年4月18日
            
            
        
                Start1     LV15
                2022年3月10日
            
            
        
                and123456     LV11
                2022年2月11日
            
            
        
                ZiruiSong     LV7
                2022年1月4日
            
            
        
                yema2986     LV2
                2021年11月18日
            
            
        
                putifeishu108     LV7
                2021年5月24日
            
            
        
 
                 
                 
                