예제 #1
0
        /// <summary>
        /// checks current cachestore for a cached response and returns it
        /// </summary>
        /// <param name="context"></param>
        /// <returns>cached response or null</returns>
        private static Response CheckCache(NancyContext context)
        {
            if (context.Request.Query is DynamicDictionary dict)
            {
                if (dict.ContainsKey(NoRequestQueryKey))
                {
                    return(null);
                }
            }

            string key = _cacheKeyGenerator.Get(context.Request);

            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            var removeRapid = context.Request.Query.removeRapid;

            if (removeRapid != null && removeRapid)
            {
                _cacheStore.Remove(key);
                return(null);
            }

            var response = _cacheStore.Get(key);

            if (response == null || response.Expiration < DateTime.UtcNow)
            {
                return(null);
            }

            new Thread(() => HandleRequest(context.Request, key))
            .Start();

            //make damn sure the pre-requirements are met before returning a cached response
            var preResponse = InvokePreRequirements(context);

            if (preResponse != null)
            {
                return(preResponse);
            }

            return(response);
        }
예제 #2
0
        /// <summary>
        /// checks current cachestore for a cached response and returns it
        /// </summary>
        /// <param name="context"></param>
        /// <returns>cached response or null</returns>
        private static Response CheckCache(NancyContext context)
        {
            if (context.Request.Query is DynamicDictionary dict)
            {
                if (DisableCache.Enabled && dict.ContainsKey(DisableCache.Key))
                {
                    return(null);
                }
            }

            string key = _cacheKeyGenerator.Get(context.Request);

            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            if (context.Request.Query is DynamicDictionary rmv)
            {
                if (RemoveCache.Enabled && rmv.ContainsKey(RemoveCache.Key))
                {
                    _cacheStore.Remove(key);
                    return(null);
                }
            }

            var response = _cacheStore.Get(key);

            if (response == null || response.Expiration < DateTime.UtcNow)
            {
                return(null);
            }

            //make damn sure the pre-requirements are met before returning a cached response
            var preResponse = InvokePreRequirements(context);

            if (preResponse != null)
            {
                return(preResponse);
            }

            return(response);
        }
        /// <summary>
        /// checks current cachestore for a cached response and returns it
        /// </summary>
        /// <param name="context"></param>
        /// <returns>cached response or null</returns>
        private static Response CheckCache(NancyContext context)
        {
            if (context.Request.Query is DynamicDictionary)
            {
                if ((context.Request.Query as DynamicDictionary).ContainsKey(NO_REQUEST_CACHE_KEY))
                {
                    return(null);
                }
            }

            var key = _cacheKeyGenerator.Get(context);

            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            var response = _cacheStore.Get(key);

            if (response == null)
            {
                return(null);
            }

            if (response.Expiration < DateTime.Now)
            {
                var t = new Thread(HandleRequestAsync);
                t.Start(context);
            }

            //make damn sure the pre-requirements are met before returning a cached response
            var preResponse = InvokePreRequirements(context);

            if (preResponse != null)
            {
                return(preResponse);
            }

            return(response);
        }