From bc1c74915271c3eabd68e9b0846cc6aa626bb4b1 Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Wed, 14 Sep 2016 10:39:56 +0800 Subject: [PATCH] --- src/org/redkale/net/http/HttpBaseServlet.java | 4 ++-- src/org/redkale/net/http/Rest.java | 18 ++++++++++++++---- src/org/redkale/net/http/RestMapping.java | 4 +++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/org/redkale/net/http/HttpBaseServlet.java b/src/org/redkale/net/http/HttpBaseServlet.java index 88fd18da8..98f76f01e 100644 --- a/src/org/redkale/net/http/HttpBaseServlet.java +++ b/src/org/redkale/net/http/HttpBaseServlet.java @@ -120,8 +120,8 @@ public abstract class HttpBaseServlet extends HttpServlet { /** * 配合 HttpBaseServlet 使用。 - * 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一定时间(默认值timeout=15秒)。 - * 通常情况下 @HttpCacheable 需要与 @AuthIgnore 一起使用,因为没有标记@AuthIgnore的方法一般输出的结果与当前用户信息有关。 + * 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一段时间(默认值timeout=15秒)。 + * 通常情况下 @HttpCacheable 需要与 @AuthIgnore 一起使用,没有标记@AuthIgnore的方法一般输出的结果与当前用户信息有关。 * *
* 详情见: http://redkale.org diff --git a/src/org/redkale/net/http/Rest.java b/src/org/redkale/net/http/Rest.java index 11a8698db..c2f5fdd8a 100644 --- a/src/org/redkale/net/http/Rest.java +++ b/src/org/redkale/net/http/Rest.java @@ -76,6 +76,7 @@ public final class Rest { final String restoutputDesc = Type.getDescriptor(RestOutput.class); final String attrDesc = Type.getDescriptor(org.redkale.util.Attribute.class); final String authDesc = Type.getDescriptor(HttpBaseServlet.AuthIgnore.class); + final String cacheDesc = Type.getDescriptor(HttpBaseServlet.HttpCacheable.class); final String actionDesc = Type.getDescriptor(HttpBaseServlet.WebAction.class); final String webparamDesc = Type.getDescriptor(HttpBaseServlet.WebParam.class); final String sourcetypeDesc = Type.getDescriptor(HttpBaseServlet.ParamSourceType.class); @@ -207,6 +208,11 @@ public final class Rest { av0 = mv.visitAnnotation(authDesc, true); av0.visitEnd(); } + if (entry.cachetimeout > 0) { //设置 HttpCacheable + av0 = mv.visitAnnotation(cacheDesc, true); + av0.visit("timeout", entry.cachetimeout); + av0.visitEnd(); + } mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, newDynName, REST_SERVICEMAP_FIELD_NAME, "Ljava/util/Map;"); @@ -340,14 +346,16 @@ public final class Rest { av3.visitEnd(); } java.lang.reflect.Type grt = method.getGenericReturnType(); - av0.visit("result", grt == returnType ? returnType.getName(): String.valueOf(grt)); + av0.visit("result", grt == returnType ? returnType.getName() : String.valueOf(grt)); av0.visitEnd(); actionMap.put("url", url); + actionMap.put("auth", entry.auth); + actionMap.put("cachetimeout", entry.cachetimeout); actionMap.put("actionid", entry.actionid); actionMap.put("comment", entry.comment); actionMap.put("methods", entry.methods); - actionMap.put("result", grt == returnType ? returnType.getName(): String.valueOf(grt)); + actionMap.put("result", grt == returnType ? returnType.getName() : String.valueOf(grt)); } List