Commit 1bf77695 by WeiCong

增加缓存机制

增加文件上传拦截
parent fcef01f2
package org.sss.presentation.noui.cache;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.sss.common.model.CacheController;
import java.util.List;
public abstract class AbstractCache implements CacheController {
protected final String cacheName;
final String SPLIT = "__";
public AbstractCache(String redis_cache) {
this.cacheName = redis_cache;
}
@Override
public List cacheRead(Object o, long keepAlive, int maxSize, int offset) {
List lst = null;
String key = generateKey(o, maxSize, offset);
lst = doCacheRead(key);
if (lst == null) {
if (o instanceof Criteria) {
Criteria criteria = (Criteria) o;
if (maxSize > 0) {
criteria.setMaxResults(maxSize);
}
if (offset > 0) {
criteria.setFirstResult(offset);
}
lst = criteria.list();
} else if (o instanceof Query) {
Query query = (Query) o;
if (maxSize > 0) {
query.setMaxResults(maxSize);
}
if (offset > 0) {
query.setFirstResult(offset);
}
lst = query.list();
}
doCacheWrite(key, lst, keepAlive);
}
return lst;
}
private String generateKey(Object o, int maxSize, int offset) {
StringBuffer sb = new StringBuffer(cacheName);
sb.append(SPLIT.intern());
sb.append(o.toString());
if (maxSize > 0) {
sb.append(SPLIT.intern());
sb.append(maxSize);
}
if (offset > 0) {
sb.append(SPLIT.intern());
sb.append(offset);
}
return sb.toString();
}
protected abstract List doCacheRead(String key);
protected abstract void doCacheWrite(String key, List lst, long keepAlive);
}
package org.sss.presentation.noui.cache;
import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.util.RedisUtil;
import java.util.List;
public class RedisCache extends AbstractCache {
public RedisCache() {
super("REDIS_CACHE");
}
@Override
protected List doCacheRead(String key) {
try {
return (List) RedisUtil.get(key);
} catch (Exception e) {
throw new NoUiException("从缓存[" + this.cacheName + "]中获取key=" + key + "的值出现异常", e);
}
}
@Override
protected void doCacheWrite(String key, List lst, long keepAlive) {
try {
RedisUtil.set(key, lst, (int) (keepAlive / 1000));
} catch (Exception e) {
throw new NoUiException("将key=" + key + "的值放入缓存[" + this.cacheName + "]出现异常", e);
}
}
@Override
public Object cacheRead(String key) {
try {
return RedisUtil.get(key);
} catch (Exception e) {
throw new NoUiException("从缓存[" + this.cacheName + "]中获取key=" + key + "的值出现异常", e);
}
}
@Override
public boolean cacheWrite(String key, Object val) {
try {
RedisUtil.set(key, val);
return true;
} catch (Exception e) {
throw new NoUiException("将key=" + key + "的值放入缓存[" + this.cacheName + "]出现异常", e);
}
}
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<configuration> <configuration>
<!-- <service class="org.sss.util.ContainerUtils" initMethodName="init" deinitMethodName="deinit"> <service class="org.sss.util.ContainerUtils" initMethodName="init" deinitMethodName="deinit">
交易DAT文件是否采用压缩 <property name="cacheClassName" value="org.sss.presentation.noui.cache.RedisCache" class="java.lang.String" />
<property name="isCompressed" value="false" class="boolean" /> <!-- 开启后台自动检核-->
日志系统是否通过JSON进行格式化 <property name="checkWithXML" value="true" class="boolean" />
<property name="jsonUsed" value="false" class="boolean" /> <!-- 未发现检查文件时返回值-->
是否采用集群通过本地MQ进行文件同步(FILE_SVR/FILE_QM/SEND_O_FILE/RECV_I_FILE) <property name="valueNoCheckXML" value="true" class="boolean" />
<property name="clusterUsed" value="false" class="boolean" /> <!-- 交易DAT文件是否采用压缩 -->
<property name="queueHostName" value="127.0.0.1" /> <!-- <property name="isCompressed" value="false" class="boolean" /> -->
<property name="remoteHostName" value="192.168.0.178" /> <!-- 日志系统是否通过JSON进行格式化 -->
<property name="queuePort" value="1419" class="int" /> <!-- <property name="jsonUsed" value="false" class="boolean" /> -->
是否让平台主动进行Java的GC收集 <!-- 是否采用集群通过本地MQ进行文件同步(FILE_SVR/FILE_QM/SEND_O_FILE/RECV_I_FILE) -->
<property name="autoGC" value="true" class="boolean" /> <!-- <property name="clusterUsed" value="false" class="boolean" /> -->
</service> --> <!-- <property name="queueHostName" value="127.0.0.1" /> -->
<!-- <property name="remoteHostName" value="192.168.0.178" /> -->
<!-- <property name="queuePort" value="1419" class="int" /> -->
<!-- 是否让平台主动进行Java的GC收集 -->
<!-- <property name="autoGC" value="true" class="boolean" /> -->
</service>
<!-- <!--
<service class="cn.com.brilliance.eibs.auth.LdapLoginContext"> <service class="cn.com.brilliance.eibs.auth.LdapLoginContext">
<property name="ldapServer" value="192.1.1.9" /> <property name="ldapServer" value="192.1.1.9" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment