public override async Task OnActionExecutionAsync( ActionExecutingContext context, ActionExecutionDelegate next) { // Do we have a IRedisService implementation? try { RedisService = context.HttpContext .RequestServices.GetService <IRedisService>(); } catch (InvalidOperationException) { // Caching has not been configured await next(); return; } // Attempt to get the response data from the Redis cache CacheKey = CacheKey.Format((IDictionary)context.ActionArguments); var result = await RedisService.GetCachedResult(CacheKey); if (result != null) { context.Result = result; return; } // Execute the action normally, and then cache the result ActionExecutedContext executedContext = await next(); await RedisService.CacheResult( CacheKey, executedContext.Result as ApiResult, expire : Expire ); }