我想通過讓它知道我在我的控制器中調用的函數的參數稍微好一點@Cached註釋。檢查結果是好的playframework
所以我有這樣的動作:
public class ContextualCachedAction extends Action<ContextualCached> {
@Override
public Result call(Context ctx) throws Throwable {
try {
String key = makeKey(ctx);
Integer duration = configuration.duration();
Result result = (Result) Cache.get(key);
if (result == null) {
result = delegate.call(ctx);
//TODO find a way to cache only successful calls
Cache.set(key, result, duration);
}
return result;
} catch (RuntimeException e) {
throw e;
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
private String makeKey(Context ctx) {
//makes the key from some parameters in the ctx.request()
}
}
我的問題是這樣的:我想緩存delegate.call的()的結果,只有當它是一個不錯的()。 我該如何檢查? 有沒有房產? util? 或者我需要Ok()。getClass()。isInstance(result)?
感謝您的任何答案和提示。
PS:爲什麼我想這樣做?因爲我有一些調用產生幾種不同的結果。很少有足夠的結果緩存他們可能是一個選擇,因爲我不想
這工作......謝謝 – 2013-02-28 16:35:23
這是推薦的方法嗎?這似乎非常尷尬和複雜,以實現一些簡單的事情,比如檢查響應狀態代碼 – knittl 2014-01-03 08:50:05
如果它不是'PlainResult'的實例呢? – jlars62 2014-09-06 20:30:44