当前位置: 首页>>代码示例>>C#>>正文


C# NancyContext.GetRequestFingerprint方法代码示例

本文整理汇总了C#中Nancy.NancyContext.GetRequestFingerprint方法的典型用法代码示例。如果您正苦于以下问题:C# NancyContext.GetRequestFingerprint方法的具体用法?C# NancyContext.GetRequestFingerprint怎么用?C# NancyContext.GetRequestFingerprint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Nancy.NancyContext的用法示例。


在下文中一共展示了NancyContext.GetRequestFingerprint方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CheckCache

 /// <summary>
 ///   Check to see if we have a cache entry - if we do, see if it has expired or not, if it
 ///   hasn't then return it, otherwise return null.
 /// </summary>
 /// <param name="context">Current context.</param>
 /// <returns>Response or null.</returns>
 Response CheckCache(NancyContext context)
 {
     var cacheKey = context.GetRequestFingerprint();
     var cachedSummary = _cache.Get<ResponseSummary>(ResponseCachePartition, cacheKey);
     return cachedSummary.HasValue ? cachedSummary.Value.ToResponse() : null;
 }
开发者ID:pomma89,项目名称:KVLite,代码行数:12,代码来源:CachingBootstrapper.cs

示例2: SetCache

        /// <summary>
        ///   Adds the current response to the cache if required Only stores by Path and stores the
        ///   response in a KVLite cache.
        /// </summary>
        /// <param name="context">Current context.</param>
        void SetCache(NancyContext context)
        {
            if (context.Response.StatusCode != HttpStatusCode.OK)
            {
                return;
            }

            object cacheSecondsObject;
            if (!context.Items.TryGetValue(ContextExtensions.OutputCacheTimeKey, out cacheSecondsObject))
            {
                return;
            }

            int cacheSeconds;
            if (!int.TryParse(cacheSecondsObject.ToString(), out cacheSeconds))
            {
                return;
            }

            // Disable further caching, as it must explicitly enabled.
            context.Items.Remove(ContextExtensions.OutputCacheTimeKey);

            // The response we are going to cache. We put it here, so that it can be used as
            // recovery in the catch clause below.
            var responseToBeCached = context.Response;

            try
            {
                var cacheKey = context.GetRequestFingerprint();
                var cachedSummary = new ResponseSummary(responseToBeCached);
                _cache.AddTimed(ResponseCachePartition, cacheKey, cachedSummary, _cache.Clock.UtcNow.AddSeconds(cacheSeconds));
                context.Response = cachedSummary.ToResponse();
            }
            catch (Exception ex)
            {
                const string errMsg = "Something bad happened while caching :-(";
                LogManager.GetLogger<CachingBootstrapper>().Error(errMsg, ex);
                // Sets the old response, hoping it will work...
                context.Response = responseToBeCached;
            }
        }
开发者ID:pomma89,项目名称:KVLite,代码行数:46,代码来源:CachingBootstrapper.cs


注:本文中的Nancy.NancyContext.GetRequestFingerprint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。