This commit is contained in:
@@ -132,7 +132,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
|
||||
/**
|
||||
* 配合 HttpBaseServlet 使用。
|
||||
* 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一段时间(默认值timeout=15秒)。
|
||||
* 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一段时间(默认值 seconds=15秒)。
|
||||
* 通常情况下 @HttpCacheable 需要与 @AuthIgnore 一起使用,没有标记@AuthIgnore的方法一般输出的结果与当前用户信息有关。
|
||||
*
|
||||
* <p>
|
||||
@@ -150,7 +150,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
*
|
||||
* @return 超时秒数
|
||||
*/
|
||||
int timeout() default 15;
|
||||
int seconds() default 15;
|
||||
}
|
||||
|
||||
private Map.Entry<String, Entry>[] actions;
|
||||
@@ -170,9 +170,9 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
return;
|
||||
}
|
||||
if (entry.ignore || authenticate(entry.moduleid, entry.actionid, request, response)) {
|
||||
if (entry.cachetimeout > 0) {//有缓存设置
|
||||
if (entry.cacheseconds > 0) {//有缓存设置
|
||||
CacheEntry ce = entry.cache.get(request.getRequestURI());
|
||||
if (ce != null && ce.time + entry.cachetimeout > System.currentTimeMillis()) { //缓存有效
|
||||
if (ce != null && ce.time + entry.cacheseconds > System.currentTimeMillis()) { //缓存有效
|
||||
response.setStatus(ce.status);
|
||||
response.setContentType(ce.contentType);
|
||||
response.finish(ce.getBuffers());
|
||||
@@ -348,9 +348,9 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
this.servlet = servlet;
|
||||
this.ignore = typeIgnore || method.getAnnotation(AuthIgnore.class) != null;
|
||||
HttpCacheable hc = method.getAnnotation(HttpCacheable.class);
|
||||
this.cachetimeout = hc == null ? 0 : hc.timeout() * 1000;
|
||||
this.cache = cachetimeout > 0 ? new ConcurrentHashMap() : null;
|
||||
this.cacheHandler = cachetimeout > 0 ? (HttpResponse response, ByteBuffer[] buffers) -> {
|
||||
this.cacheseconds = hc == null ? 0 : hc.seconds() * 1000;
|
||||
this.cache = cacheseconds > 0 ? new ConcurrentHashMap() : null;
|
||||
this.cacheHandler = cacheseconds > 0 ? (HttpResponse response, ByteBuffer[] buffers) -> {
|
||||
int status = response.getStatus();
|
||||
if (status != 200) return null;
|
||||
CacheEntry ce = new CacheEntry(response.getStatus(), response.getContentType(), buffers);
|
||||
@@ -375,7 +375,7 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
|
||||
public final ConcurrentHashMap<String, CacheEntry> cache;
|
||||
|
||||
public final int cachetimeout;
|
||||
public final int cacheseconds;
|
||||
|
||||
public final boolean ignore;
|
||||
|
||||
|
||||
@@ -221,9 +221,9 @@ public final class Rest {
|
||||
av0 = mv.visitAnnotation(authDesc, true);
|
||||
av0.visitEnd();
|
||||
}
|
||||
if (entry.cachetimeout > 0) { //设置 HttpCacheable
|
||||
if (entry.cacheseconds > 0) { //设置 HttpCacheable
|
||||
av0 = mv.visitAnnotation(cacheDesc, true);
|
||||
av0.visit("timeout", entry.cachetimeout);
|
||||
av0.visit("seconds", entry.cacheseconds);
|
||||
av0.visitEnd();
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ public final class Rest {
|
||||
av0.visitEnd();
|
||||
actionMap.put("url", url);
|
||||
actionMap.put("auth", entry.auth);
|
||||
actionMap.put("cachetimeout", entry.cachetimeout);
|
||||
actionMap.put("cachetimeout", entry.cacheseconds);
|
||||
actionMap.put("actionid", entry.actionid);
|
||||
actionMap.put("comment", entry.comment);
|
||||
actionMap.put("methods", entry.methods);
|
||||
@@ -1018,7 +1018,7 @@ public final class Rest {
|
||||
this.methods = mapping.methods();
|
||||
this.auth = mapping.auth();
|
||||
this.actionid = mapping.actionid();
|
||||
this.cachetimeout = mapping.cachetimeout();
|
||||
this.cacheseconds = mapping.cacheseconds();
|
||||
this.comment = mapping.comment();
|
||||
this.jsvar = mapping.jsvar();
|
||||
}
|
||||
@@ -1037,7 +1037,7 @@ public final class Rest {
|
||||
|
||||
public final int actionid;
|
||||
|
||||
public final int cachetimeout;
|
||||
public final int cacheseconds;
|
||||
|
||||
public final String jsvar;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public @interface RestMapping {
|
||||
|
||||
int actionid() default 0; //操作ID值,鉴权时用到, 对应@WebAction.actionid
|
||||
|
||||
int cachetimeout() default 0; // 结果缓存的秒数, 为0表示不缓存, 对应@HttpCacheable.timeout
|
||||
int cacheseconds() default 0; // 结果缓存的秒数, 为0表示不缓存, 对应@HttpCacheable.seconds
|
||||
|
||||
String[] methods() default {};//允许方法(不区分大小写),如:GET/POST/PUT,为空表示允许所有方法, 对应@WebAction.methods
|
||||
|
||||
|
||||
Reference in New Issue
Block a user