/// <summary> /// Proceeds the caching. /// </summary> /// <param name="invocation">Invocation.</param> /// <param name="attribute">Attribute.</param> private void ProceedCaching(IInvocation invocation, EasyCachingInterceptorAttribute attribute) { var cacheKey = GenerateCacheKey(invocation); var cacheValue = _cacheProvider.Get <object>(cacheKey); if (cacheValue.HasValue) { invocation.ReturnValue = cacheValue.Value; return; } invocation.Proceed(); if (!string.IsNullOrWhiteSpace(cacheKey)) { _cacheProvider.Set(cacheKey, invocation.ReturnValue, TimeSpan.FromSeconds(attribute.Expiration)); } }
/// <summary> /// Proceeds the caching. /// </summary> /// <returns>The caching.</returns> /// <param name="context">Context.</param> /// <param name="next">Next.</param> /// <param name="attribute">Attribute.</param> private async Task ProceedCaching(AspectContext context, AspectDelegate next, EasyCachingInterceptorAttribute attribute) { var cacheKey = GenerateCacheKey(context, attribute.ParamCount); var cacheValue = CacheProvider.Get <object>(cacheKey, null, TimeSpan.FromSeconds(attribute.Expiration)); if (cacheValue.HasValue) { context.ReturnValue = cacheValue.Value; return; } await next(context); if (!string.IsNullOrWhiteSpace(cacheKey)) { CacheProvider.Set(cacheKey, context.ReturnValue, TimeSpan.FromSeconds(attribute.Expiration)); } }