public override async Task Invoke(AspectContext context, AspectDelegate next) { var cacheKey = context.GetMethodFullName(); //核心1:注意这里和之前不同,是获取的string值,之前是object var cacheValue = await RedisHelper.GetStringAsync(cacheKey); //将当前获取到的缓存值,赋值给当前执行方法 var type = context.ImplementationMethod.ReturnType; if (cacheValue != null) { object response; dynamic temp = JsonConvert.DeserializeObject(cacheValue, type); response = Task.FromResult(temp); context.ReturnValue = response; return; } //去执行当前的方法 await next(context); // 核心5:将获取到指定的response 和特性的缓存时间,进行set操作 await RedisHelper.SetObjectAsync(cacheKey, context.ReturnValue); }