Ninject と AOP を使用してキャッシングを行っています。リポジトリ内の任意のメソッドに適用できる属性があり、BeforeInvoke ではキャッシュされたオブジェクトがあればそれを返し、AfterInvoke はキャッシュされたオブジェクトを作成します。これはすべてうまく機能しますが、初期メソッドの呼び出しを停止する方法がわかりません。つまり、キャッシュされたオブジェクトがある場合、intyercepted メソッドを呼び出す代わりにそれを返します。私のインターセプターはここにあります:
public class CacheInterceptor : SimpleInterceptor
{
protected override void BeforeInvoke(IInvocation invocation)
{
Type returnType = invocation.Request.Method.ReturnType;
string cacheKey = CacheKeyBuilder.GetCacheKey(invocation, serializer);
object cachedValue = cache.Get(cacheKey);
if (cachedValue == null)
{
invocation.Proceed();
}
else
{
object returnValue = serializer.Deserialize(returnType, cachedValue);
invocation.ReturnValue = returnValue;
returnedCachedResult = true;
}
}
}
else ステートメントでは、呼び出されたメソッド 'invocation.Proceed();' を呼び出すように明確に言っていません。それはまだそれを呼び出します。ninject に invocation.ReturnValue で戻るように指示するにはどうすればよいですか?