com.base4j.cache.store.SuperCache Maven / Gradle / Ivy
package com.base4j.cache.store;
import java.util.List;
import java.util.concurrent.Callable;
import org.springframework.cache.support.SimpleValueWrapper;
import com.base4j.cache.Cache;
import com.base4j.cache.CacheException;
import com.base4j.cache.Base4jCacheManager;
import com.base4j.cache.store.ehcache.EhCache;
import com.base4j.cache.store.redis.RedisCache;
public class SuperCache extends Base4jCacheManager implements Cache {
private EhCache ehCache;
private RedisCache redisCache;
private Base4jCacheManager jeezzCacheManager;
public SuperCache() {
super();
}
public Base4jCacheManager getJeezzCacheManager() {
return jeezzCacheManager;
}
public void setJeezzCacheManager(Base4jCacheManager jeezzCacheManager) {
this.jeezzCacheManager = jeezzCacheManager;
}
public EhCache getEhCache() {
return ehCache;
}
public RedisCache getRedisCache() {
return redisCache;
}
public void setEhCache(EhCache ehCache) {
this.ehCache = ehCache;
}
public void setRedisCache(RedisCache redisCache) {
this.redisCache = redisCache;
}
@Override
public String getName() {
// TODO Auto-generated method stub
System.out.println("111");
return null;
}
@Override
public Object getNativeCache() {
System.out.println("222");
return null;
}
@Override
public ValueWrapper get(Object key) {
Object gets = ehCache.gets(key);
if (gets == null) {
gets = redisCache.gets(key);
}
if (gets != null) {
ehCache.put(key, gets);
return toValueWrapper(gets);
}
return null;
}
private ValueWrapper toValueWrapper(Object object) {
return (object != null ? new SimpleValueWrapper(object) : null);
}
@Override
public T get(Object key, Class type) {
// TODO Auto-generated method stub
System.out.println("444");
return null;
}
@Override
public T get(Object key, Callable valueLoader) {
// TODO Auto-generated method stub
System.out.println("555");
return null;
}
@Override
public ValueWrapper putIfAbsent(Object key, Object value) {
put(key, value);
Object gets = gets(key);
return toValueWrapper(gets);
}
@Override
public Object gets(Object key) throws CacheException {
// TODO Auto-generated method stub
return null;
}
@Override
public void put(Object key, Object value) throws CacheException {
try {
ehCache.put(key, value);
Object gets = ehCache.gets(key);
if (gets != null && redisCache != null) {
redisCache.put(key, value);
//sendCmdBroadcast(CacheCustoms.OPT_DELTED_KEY, "", key);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void evict(Object key) throws CacheException {
ehCache.evict(key);
if (redisCache != null) {
redisCache.evict(key);
//sendCmdBroadcast(CacheCustoms.OPT_DELTED_KEY, "", key);
}
}
@Override
public void evict(List keys) throws CacheException {
ehCache.evict(keys);
if (redisCache != null) {
redisCache.evict(keys);
//sendCmdBroadcast(CacheCustoms.OPT_DELTED_KEY, "", keys);
}
}
@Override
public List keys() throws CacheException {
return ehCache.keys();
}
@Override
public void clear() throws CacheException {
ehCache.clear();
if (redisCache != null) {
redisCache.clear();
//getFactory().getCache(CacheCustoms.CACHE_LV_2, "", true, null).clear();
}
}
@Override
public void destroy() throws CacheException {
ehCache.destroy();
if (redisCache != null) {
redisCache.destroy();
}
}
}