示例#1
0
        public override async Task OnActionExecutedAsync(HttpActionExecutedContext actionExecutedContext,
                                                         CancellationToken cancellationToken)
        {
            var cacheKey = actionExecutedContext.ActionContext.ActionArguments.ToCacheKey();
            var content  = await actionExecutedContext.Response.Content.ReadAsStringAsync();

            if (cacheOnClient)
            {
                var eTag = GetETag(cacheKey);
                actionExecutedContext.ActionContext.Response.Headers.ETag = new EntityTagHeaderValue(GetETag(cacheKey));
                await cache.PutAsync(cacheKey, eTag, TimeSpan.FromMilliseconds(timeoutMilliseconds));
            }
            else
            {
                await cache.PutAsync(cacheKey, content, TimeSpan.FromMilliseconds(timeoutMilliseconds));
            }
        }
        public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout)
        {
            var    sessionItems  = new SessionStateItemCollection();
            string sessionString = JsonConvert.SerializeObject(sessionItems);

            cache.PutAsync(context.Session.SessionID, sessionString, TimeSpan.FromMinutes(timeout));
            var data = new SessionStateStoreData(sessionItems, null, timeout);

            return(data);
        }
        public async Task PutAsync <T>(string key, T value, TimeSpan lifeSpan)
        {
            if (PrePut != null)
            {
                PrePut(this, new PutEventArgs(key, value, lifeSpan));
            }
            await targetCache.PutAsync(key, value, lifeSpan);

            if (PostPut != null)
            {
                PostPut(this, new PutEventArgs(key, value, lifeSpan));
            }
        }