com.litongjava.tio.utils.cache.j2cache.J2Cache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tio-utils Show documentation
Show all versions of tio-utils Show documentation
t-io is a aio framework for java
package com.litongjava.tio.utils.cache.j2cache;
import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import com.litongjava.tio.utils.cache.AbsCache;
import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
/**
* 红薯家的j2cache
* @author tanyaowu
*
*/
public class J2Cache extends AbsCache {
public J2Cache(String cacheName) {
super(cacheName);
}
private static CacheChannel getChannel() {
CacheChannel cache = net.oschina.j2cache.J2Cache.getChannel();
return cache;
}
@Override
public void clear() {
CacheChannel cache = getChannel();
cache.clear(cacheName);
}
@Override
public Serializable _get(String key) {
CacheChannel cache = getChannel();
CacheObject cacheObject = cache.get(cacheName, key);
if (cacheObject != null) {
return (Serializable) cacheObject.getValue();
}
return null;
}
@Override
public Collection keys() {
CacheChannel cache = getChannel();
return cache.keys(cacheName);
}
@Override
public Collection keysCollection() {
return getChannel().keys(cacheName);
}
@Override
public void put(String key, Serializable value) {
CacheChannel cache = getChannel();
cache.set(cacheName, key, value);
}
@Override
public void remove(String key) {
CacheChannel cache = getChannel();
cache.evict(cacheName, key);
}
@Override
public void putTemporary(String key, Serializable value) {
throw new RuntimeException("不支持防缓存穿透");
}
@Override
public long ttl(String key) {
throw new RuntimeException("不支持ttl");
}
@Override
public Map asMap() {
// Collection keys = getChannel().keys(cacheName);
// Map map = getChannel().get(cacheName, keys);
// return map;
return null;
}
@Override
public long size() {
CacheChannel channel = getChannel();
return channel.keys(cacheName).size();
}
}