use of act.controller.ResponseCache in project actframework by actframework.
the class ActionContext method enableCache.
public ActionContext enableCache() {
E.illegalArgumentIf(this.cacheEnabled, "cache already enabled in the action context");
this.cacheEnabled = true;
this.response = new ResponseCache(response);
return this;
}
use of act.controller.ResponseCache in project actframework by actframework.
the class RequestHandlerProxy method handle.
@Override
public void handle(ActionContext context) {
ensureAgentsReady();
context.handlerMethod(actionMethod);
if (null != webSocketConnectionHandler) {
webSocketConnectionHandler.handle(context);
return;
}
Result result = null;
try {
H.Method method = context.req().method();
boolean supportCache = this.supportCache && method == GET || (cacheSupport.supportPost && method == POST);
String cacheKey = null;
if (supportCache) {
cacheKey = cacheSupport.cacheKey(context);
ResponseCache cached = this.cache.get(cacheKey);
if (null != cached) {
cached.applyTo(context.prepareRespForWrite());
return;
}
context.enableCache();
}
saveActionPath(context);
context.startIntercepting();
result = handleBefore(context);
if (null == result) {
context.startHandling();
result = _handle(context);
}
if (context.resp().isClosed()) {
return;
}
context.startIntercepting();
Result afterResult = handleAfter(result, context);
if (null != afterResult) {
result = afterResult;
}
if (null == result) {
result = context.nullValueResult();
}
onResult(result, context);
if (supportCache) {
this.cache.put(cacheKey, context.resp(), cacheSupport.ttl);
}
} catch (Exception e) {
H.Request req = context.req();
logger.error(e, S.concat("Error handling request: [", req.method().name(), "] ", req.url()));
try {
result = handleException(e, context);
} catch (Exception e0) {
logger.error(e0, "Error invoking exception handler");
}
if (null == result) {
result = ActErrorResult.of(e);
}
try {
onResult(result, context);
} catch (Exception e2) {
logger.error(e2, "error rendering exception handle result");
onResult(ActErrorResult.of(e2), context);
}
} finally {
try {
handleFinally(context);
} catch (Exception e) {
logger.error(e, "Error invoking final handler");
} finally {
context.destroy();
}
}
}
Aggregations