Exemplo n.º 1
0
        public static CacheWrapper <TSource> SetCache <TSource>(this CacheWrapper <TSource> cacheWrapper, List <TSource> caches, CacheType cacheType, KolibreCacheOptions options) where TSource : class
        {
            if (cacheWrapper == null)
            {
                throw new ArgumentNullException(nameof(cacheWrapper));
            }

            cacheWrapper.Caches    = caches;
            cacheWrapper.CacheType = cacheType;

            if (!cacheWrapper.AbsoluteExpiration.HasValue)
            {
                cacheWrapper.AbsoluteExpiration = options.AbsoluteExpiration.HasValue ? options.AbsoluteExpiration.Value : DateTimeOffset.MaxValue;
            }
            if (!cacheWrapper.SlidingExpiration.HasValue)
            {
                cacheWrapper.SlidingExpiration = options.SlidingExpiration;
            }
            if (cacheWrapper.SlidingExpiration.HasValue)
            {
                cacheWrapper.SlidingExpirationTime = DateTimeOffset.UtcNow.ToChinaStandardTime().Add(cacheWrapper.SlidingExpiration.Value);
            }

            return(cacheWrapper);
        }
Exemplo n.º 2
0
        public static CacheWrapper SetCache(this CacheWrapper cacheWrapper, string cache, CacheType cacheType, KolibreCacheOptions options)
        {
            if (cacheWrapper == null)
            {
                throw new ArgumentNullException(nameof(cacheWrapper));
            }

            cacheWrapper.Cache     = cache;
            cacheWrapper.CacheType = cacheType;

            if (!cacheWrapper.AbsoluteExpiration.HasValue)
            {
                cacheWrapper.AbsoluteExpiration = options.AbsoluteExpiration.HasValue ? options.AbsoluteExpiration.Value : DateTimeOffset.MaxValue;
            }
            if (!cacheWrapper.SlidingExpiration.HasValue)
            {
                cacheWrapper.SlidingExpiration = options.SlidingExpiration;
            }
            if (cacheWrapper.SlidingExpiration.HasValue)
            {
                cacheWrapper.SlidingExpirationTime = DateTimeOffset.UtcNow.ToChinaStandardTime().Add(cacheWrapper.SlidingExpiration.Value);
            }

            return(cacheWrapper);
        }