public void OnResultExecuting(ResultExecutingContext context)
        {
            if (context.HttpContext.Request.Method.ToLower() != "get")
            {
                return;
            }
            if (!(context.Result is OkObjectResult result))
            {
                return;
            }

            var cacheKey = DistributedCacheUtils.GetKey(context.HttpContext);

            if (_distributedCache.Get(cacheKey) == null)
            {
                _distributedCache.Set(cacheKey, DistributedCacheUtils.ObjectToByteArray(result.Value));
            }
        }
Exemplo n.º 2
0
        public void OnResourceExecuting(ResourceExecutingContext context)
        {
            if (context.HttpContext.Request.Method.ToLower() != "get")
            {
                return;
            }

            var cacheKey = DistributedCacheUtils.GetKey(context.HttpContext);

            var bytes = _distributedCache.Get(cacheKey);

            if (bytes == null)
            {
                return;
            }
            var byteArrayToObject = DistributedCacheUtils.ByteArrayToObject <object>(bytes);

            context.Result = new JsonResult(byteArrayToObject);
        }