public void HandleDataRequest(IInvocation invocation) { var returnType = invocation.Method.ReturnType; if (returnType != typeof(void)) { string cacheKey; if (_cacheContainer != null && _cacheContainer.CacheKeyGenerator.TryBuildCacheKey(invocation.Method, invocation.Arguments, out cacheKey)) { object result; if (_cacheContainer.TryGet(cacheKey, out result)) { invocation.ReturnValue = result; } else { invocation.Proceed(); object returnValue = invocation.ReturnValue; if (returnType.IsGenericType && returnType.GetGenericTypeDefinition() == typeof(Task <>)) { var task = (Task)returnValue; task.ContinueWith(_ => { _cacheContainer.TryAdd(cacheKey, returnValue, InvalidationConfiguration.CacheItemPolicy); }); } else { _cacheContainer.TryAdd(cacheKey, returnValue, InvalidationConfiguration.CacheItemPolicy); } } } } }