문제

i've got simple method with no parameters:

[Cache]
private void Get()
{
   int id = 5;
   var c = GetCustomerService(id);
}

I would like to Cache this method for different "id"s. "id" isn't parameter of this method. Is there any chance to call OnInvoke() using my id argument to calculate proper CacheKey??

thx4help

도움이 되었습니까?

해결책

I understand that your Cache attribute is MethodInterceptionAspect. During interception your aspect's OnInvoke code is actually executed first and then it can continue with executing your original method. It seems that what you're asking about is the opposite - calling OnInvoke back from the original Get method. This is of course is not possible.

You can perform some refactoring by creating a new method with all the parameters that define the caching key. Then inside your OnInvoke method you can just use MethodInterceptionArgs.Arguments to build the caching key.

private T Get()
{
   int id = 5;
   return GetInternal(id);
}

[Cache]
private T GetInternal(int id)
{
   return GetCustomerService(id);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top