Esempio n. 1
0
        protected async Task TryGetRevalidatedResult(IHandlerContextWithResult handlerContext, HttpRequestMessage request, HttpResponseMessage response)
        {
            if (!Enabled)
            {
                return;
            }

            var context = GetContext(handlerContext);

            var result = (CacheEntry)context.Items["CacheHandlerCachedItem"];

            var meta = CachingHelpers.CreateResponseMetadata(result, request, response, context);

            if (result == null || !context.RevalidateValidator(context, meta))
            {
                return;
            }

            if (!result.IsEmpty && result.Value != null)
            {
                result.UpdateResponseMetadata(request, response, context);

                context.ResultInspector?.Invoke(result);
            }
            else
            {
                result = CacheEntry.Empty;
            }

            if (result.IsEmpty)
            {
                var missedResult = await context.HandlerRegister.OnMiss(context);

                if (missedResult.IsDirty)
                {
                    result = new CacheEntry(missedResult.Value, null);
                }
            }

            if (!result.IsEmpty)
            {
                var hitResult = await context.HandlerRegister.OnHit(context, result.Value);

                if (hitResult.IsDirty && !(bool)hitResult.Value)
                {
                    handlerContext.Result = result.Value;
                }
            }

            context.Items["CacheHandlerCachedItem"] = result;
        }
Esempio n. 2
0
 public void UpdateResponseMetadata(HttpRequestMessage request, HttpResponseMessage response, ICacheMetadata metadata)
 {
     Metadata = CachingHelpers.CreateResponseMetadata(Value, request, response, metadata);
 }
Esempio n. 3
0
 public CacheEntry(object result, HttpRequestMessage request, HttpResponseMessage response, ICacheMetadata metadata)
     : this(result, CachingHelpers.CreateResponseMetadata(result, request, response, metadata))
 {
 }