Skip to content

Commit f9e4a73

Browse files
committed
1 parent 9364340 commit f9e4a73

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/main/java/act/handler/builtin/controller/impl/ReflectedHandlerInvoker.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public Result handle(ActionContext context) throws Exception {
235235
}
236236

237237
context.attribute("reflected_handler", this);
238-
if (null != templateContext) {
238+
if (null != templateContext && context.state().isHandling()) {
239239
context.templateContext(templateContext);
240240
}
241241
preventDoubleSubmission(context);
@@ -456,7 +456,7 @@ private Object controllerInstance(ActionContext context) {
456456
private void initCacheParams() {
457457
CacheFor cacheFor = method.getAnnotation(CacheFor.class);
458458
cacheSupport = null == cacheFor ? CacheSupportMetaInfo.disabled() : CacheSupportMetaInfo.enabled(
459-
new CacheKeyBuilder(cacheFor, method.getName()),
459+
new CacheKeyBuilder(cacheFor, S.concat(controllerClass.getName(), ".", method.getName())),
460460
cacheFor.value(),
461461
cacheFor.supportPost()
462462
);
@@ -604,7 +604,7 @@ public NotFound notFoundOnMethod(String message) {
604604

605605
private boolean checkTemplate(ActionContext context) {
606606
if (!context.state().isHandling()) {
607-
// we don't check template on interceptors
607+
//we don't check template on interceptors
608608
return false;
609609
}
610610
Boolean hasTemplate = context.hasTemplate();
@@ -879,20 +879,31 @@ protected void releaseResources() {
879879

880880
private static class CacheKeyBuilder extends $.F1<ActionContext, String> {
881881
private String[] keys;
882-
private final String methodName;
882+
private final String base;
883883

884-
CacheKeyBuilder(CacheFor cacheFor, String methodName) {
885-
this.methodName = methodName;
884+
CacheKeyBuilder(CacheFor cacheFor, String actionPath) {
885+
this.base = base(actionPath);
886886
this.keys = cacheFor.keys();
887887
}
888888

889+
private String base(String actionPath) {
890+
S.Buffer buffer = S.newBuffer();
891+
String[] sa = actionPath.split("\\.");
892+
for (String s : sa) {
893+
buffer.append(s.charAt(0));
894+
}
895+
buffer.append(actionPath.hashCode());
896+
return buffer.toString();
897+
}
898+
889899
@Override
890900
public String apply(ActionContext context) throws NotAppliedException, Osgl.Break {
891901
TreeMap<String, String> keyValues = keyValues(context);
892-
S.Buffer buffer = S.newBuffer(methodName);
902+
S.Buffer buffer = S.newBuffer(base);
893903
for (Map.Entry<String, String> entry : keyValues.entrySet()) {
894904
buffer.append("-").append(entry.getKey()).append(":").append(entry.getValue());
895905
}
906+
buffer.append(context.userAgent().isMobile() ? "M" : "B");
896907
return buffer.toString();
897908
}
898909

src/main/java/act/util/ActContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface ActContext<CTX_TYPE extends ActContext> extends ParamValueProvi
7070
/**
7171
* Set template context
7272
* @param context the path to template context
73-
* @return this {@code AppContext}
73+
* @return this {@code ActContext}
7474
*/
7575
CTX_TYPE templateContext(String context);
7676

@@ -206,7 +206,7 @@ public String templatePath() {
206206

207207
@Override
208208
public CTX templatePath(String templatePath) {
209-
template = null;
209+
this.template = null;
210210
this.templatePath = templatePath;
211211
return me();
212212
}
@@ -216,7 +216,7 @@ public String templateContext() {
216216
}
217217

218218
public CTX templateContext(String templateContext) {
219-
template = null;
219+
this.template = null;
220220
this.templateContext = templateContext;
221221
return me();
222222
}

0 commit comments

Comments
 (0)