コード例 #1
0
ファイル: CacheWrapper.cs プロジェクト: Damon227/SFActorCache
 public CacheWrapper Refresh(KolibreCacheOptions options)
 {
     AbsoluteExpiration    = options.AbsoluteExpiration;
     SlidingExpiration     = options.SlidingExpiration;
     SlidingExpirationTime = options.SlidingExpiration.HasValue ? DateTimeOffset.UtcNow.ToChinaStandardTime().Add(options.SlidingExpiration.Value) : DateTimeOffset.UtcNow.ToChinaStandardTime();
     return(this);
 }
コード例 #2
0
ファイル: CacheWrapper.cs プロジェクト: Damon227/SFActorCache
        public static CacheWrapper BuildCacheWrapper(string cache, CacheType cacheType, KolibreCacheOptions options)
        {
            if (options == null)
            {
                return(new CacheWrapper
                {
                    Cache = cache,
                    CacheType = cacheType,
                    InitializationTime = DateTimeOffset.UtcNow.ToChinaStandardTime(),
                    AbsoluteExpiration = DateTimeOffset.MaxValue
                });
            }

            return(new CacheWrapper
            {
                Cache = cache,
                CacheType = cacheType,
                InitializationTime = DateTimeOffset.UtcNow.ToChinaStandardTime(),
                AbsoluteExpiration = options.AbsoluteExpiration,
                SlidingExpiration = options.SlidingExpiration,
                SlidingExpirationTime = options.SlidingExpiration.HasValue ? DateTimeOffset.UtcNow.ToChinaStandardTime().Add(options.SlidingExpiration.Value) : DateTimeOffset.UtcNow.ToChinaStandardTime()
            });
        }
コード例 #3
0
ファイル: CacheWrapper.cs プロジェクト: Damon227/SFActorCache
        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);
        }
コード例 #4
0
ファイル: CacheWrapper.cs プロジェクト: Damon227/SFActorCache
        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);
        }