Exemplo n.º 1
0
        public Task RenewAsync(string key, AuthenticationTicket ticket) {
            var options = new MemoryCacheEntryOptions();
            var expiresUtc = ticket.Properties.ExpiresUtc;
            if(expiresUtc.HasValue) {
                options.SetAbsoluteExpiration(expiresUtc.Value);
            }
            options.SetSlidingExpiration(TimeSpan.FromHours(1)); // TODO: configurable.

            _cache.Set(key, ticket, options);

            return Task.FromResult(0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds inherited token and absolute expiration information.
        /// </summary>
        /// <param name="link"></param>
        public static MemoryCacheEntryOptions AddEntryLink(this MemoryCacheEntryOptions options, IEntryLink link)
        {
            foreach (var expirationToken in link.ExpirationTokens)
            {
                options.AddExpirationToken(expirationToken);
            }

            if (link.AbsoluteExpiration.HasValue)
            {
                options.SetAbsoluteExpiration(link.AbsoluteExpiration.Value);
            }
            return(options);
        }
Exemplo n.º 3
0
 internal static void AddIdentityToCache(Guid userId, ErpIdentity identity)
 {
     var options = new MemoryCacheEntryOptions();
     options.SetAbsoluteExpiration(TimeSpan.FromMinutes(5));
     cache.Set(userId.ToString(), identity, options);
 }
Exemplo n.º 4
0
        // Internal for unit testing
        internal MemoryCacheEntryOptions GetMemoryCacheEntryOptions()
        {
            var options = new MemoryCacheEntryOptions();
            if (ExpiresOn != null)
            {
                options.SetAbsoluteExpiration(ExpiresOn.Value);
            }

            if (ExpiresAfter != null)
            {
                options.SetAbsoluteExpiration(ExpiresAfter.Value);
            }

            if (ExpiresSliding != null)
            {
                options.SetSlidingExpiration(ExpiresSliding.Value);
            }

            if (Priority != null)
            {
                options.SetPriority(Priority.Value);
            }

            return options;
        }
Exemplo n.º 5
0
 private static void AddObjectToCache(string key, object obj)
 {
     var options = new MemoryCacheEntryOptions();
     options.SetAbsoluteExpiration(TimeSpan.FromHours(1));
     cache.Set(key, obj, options);
 }