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

📄 idcachesvcimpl.java

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

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

import org.apache.commons.lang.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jeecms.core.service.IdCacheSvc;

@Service
public class IdCacheSvcImpl implements IdCacheSvc {
	public void put(Long id, String key, String... otherKeys) {
		commonIdCache.put(new Element(getKey(key, otherKeys), id));
	}

	public Long get(String key, String... otherKeys) {
		Element e = commonIdCache.get(getKey(key, otherKeys));
		if (e != null) {
			return (Long) e.getValue();
		} else {
			return null;
		}
	}

	public boolean remove(String key, String... otherKeys) {
		return commonIdCache.remove(getKey(key, otherKeys));
	}

	private String getKey(String key, String... otherKeys) {
		if (ArrayUtils.isEmpty(otherKeys)) {
			return key;
		} else {
			StringBuilder buf = new StringBuilder(key).append(SPLIT);
			for (String s : otherKeys) {
				buf.append(s).append(SPLIT);
			}
			return buf.toString();
		}
	}

	@Autowired
	@Qualifier("commonId")
	private Cache commonIdCache;
}

⌨️ 快捷键说明

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