mirror of https://github.com/abpframework/abp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
973 B
38 lines
973 B
using System.Collections.Concurrent;
|
|
using System.Reflection;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Volo.Abp.DynamicProxy
|
|
{
|
|
public class SimpleResultCacheTestInterceptor : AbpInterceptor
|
|
{
|
|
private readonly ConcurrentDictionary<MethodInfo, object> _cache;
|
|
|
|
public SimpleResultCacheTestInterceptor()
|
|
{
|
|
_cache = new ConcurrentDictionary<MethodInfo, object>();
|
|
}
|
|
|
|
public override void Intercept(IAbpMethodInvocation invocation)
|
|
{
|
|
invocation.ReturnValue = _cache.GetOrAdd(invocation.Method, m =>
|
|
{
|
|
invocation.Proceed();
|
|
return invocation.ReturnValue;
|
|
});
|
|
}
|
|
|
|
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
|
|
{
|
|
if (_cache.ContainsKey(invocation.Method))
|
|
{
|
|
invocation.ReturnValue = _cache[invocation.Method];
|
|
return;
|
|
}
|
|
|
|
await invocation.ProceedAsync();
|
|
_cache[invocation.Method] = invocation.ReturnValue;
|
|
}
|
|
}
|
|
}
|