public static void Enable(IPipelines pipelines)
        {
            var store = new MemoryCacheBasedSessions(MemoryCache.Default);

            pipelines.BeforeRequest.AddItemToStartOfPipeline(ctx => LoadSession(ctx, store));
            pipelines.AfterRequest.AddItemToEndOfPipeline(ctx => SaveSession(ctx, store));
        }
        private static void SaveSession(NancyContext context, MemoryCacheBasedSessions sessionStore)
        {
            string sessionId;

            if (context.Request.Cookies.ContainsKey(SessionIdKey))
            {
                sessionId = context.Request.Cookies[SessionIdKey];
            }
            else
            {
                sessionId = Guid.NewGuid().ToString();
            }

            sessionStore.Save(sessionId, context.Request.Session, context.Response);
        }
        /// <summary>
        /// Loads the request session
        /// </summary>
        /// <param name="context">Nancy context</param>
        /// <param name="sessionStore">Session store</param>
        /// <returns>Always returns null</returns>
        private static Response LoadSession(NancyContext context, MemoryCacheBasedSessions sessionStore)
        {
            context.Request.Session = sessionStore.Load(context);

            return(null);
        }