コントローラで呼び出す関数のパラメータを認識させることで、より良い@Cachedアノテーションを作成しようとしています。結果がokであることを確認する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(の結果をキャッシュしたいと思います)、それはOK(ある場合のみ)。 どうすれば確認できますか? プロパティはありますか? a util? またはOK()。getClass()。isInstance(result)にする必要がありますか?
ご回答いただきありがとうございます。
PS:なぜ私はそれをしたいですか?私はいくつかの種類の結果を生成する呼び出しをいくつか持っているからです。私は
ありがとう –
これを行うには、これをお勧めしますか?これは、応答ステータスコードをチェックするのと同じような単純なものを達成するのは、実際には面倒で複雑なようです。 – knittl
'PlainResult'のインスタンスではない場合はどうなりますか? – jlars62