📄 idcachesvcimpl.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 + -