⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 channelcachesvcimpl.java

📁 为用户提供透明的管理平台
💻 JAVA
字号:
package com.jeecms.cms.service.impl;

import java.io.Serializable;

import net.sf.ehcache.Cache;
import net.sf.ehcache.Element;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jeecms.cms.service.ChannelCacheSvc;

@Service
public class ChannelCacheSvcImpl implements ChannelCacheSvc {
	public void put(Serializable key, byte[] bytes) {
		channelCache.put(new Element(key, bytes));
	}

	public byte[] get(Serializable key) {
		Element e = channelCache.get(key);
		if (e != null) {
			return (byte[]) e.getValue();
		} else {
			return null;
		}
	}

	public String getKey(Long webId, String chnlPath, int pageNo) {
		return new StringBuilder(String.valueOf(webId)).append(SPLIT).append(
				chnlPath).append(SPLIT).append(pageNo).append(SPLIT).toString();
	}

	public void put(Long webId, String chnlPath, int pageNo, byte[] bytes) {
		channelCache.put(new Element(getKey(webId, chnlPath, pageNo), bytes));
	}

	public byte[] get(Long webId, String chnlPath, int pageNo) {
		return get(getKey(webId, chnlPath, pageNo));
	}

	public int remove(Long webId) {
		String begin = String.valueOf(webId) + SPLIT;
		return remove(begin);
	}

	public int remove(Long webId, String chnlPath) {
		String begin = String.valueOf(webId) + SPLIT + chnlPath + SPLIT;
		return remove(begin);
	}

	public boolean remove(Long webId, String chnlPath, int pageNo) {
		return channelCache.remove(getKey(webId, chnlPath, pageNo));
	}

	private int remove(String begin) {
		int count = 0;
		for (Object key : channelCache.getKeys()) {
			String k = (String) key;
			if (k.startsWith(begin)) {
				count++;
				channelCache.remove(k);
			}
		}
		return count;
	}

	@Autowired
	public void setChannelCache(@Qualifier("channel") Cache channelCache) {
		this.channelCache = channelCache;
	}

	private Cache channelCache;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -