コード例 #1
0
        public static SimpleCacheOptions <TKey, TValue> WithValueFactory <TKey, TValue>(
            this SimpleCacheOptions <TKey, TValue> options, Func <TKey, IServiceProvider, CancellationToken, Task <TValue?> > valueFactory) where TValue : class
        {
            options.ValueFactory = valueFactory;

            return(options);
        }
コード例 #2
0
        public static SimpleCacheOptions <TValue> WithSlidingExpiration <TValue>(this SimpleCacheOptions <TValue> options, TimeSpan slidingExpiration) where TValue : class
        {
            if (options.DefaultEntryOptions == null)
            {
                options.DefaultEntryOptions = new DistributedCacheEntryOptions();
            }

            options.DefaultEntryOptions.SlidingExpiration = slidingExpiration;

            return(options);
        }
コード例 #3
0
        public static SimpleCacheOptions <TValue> WithAbsoluteExpiration <TValue>(this SimpleCacheOptions <TValue> options, DateTimeOffset absoluteExpiration) where TValue : class
        {
            if (options.DefaultEntryOptions == null)
            {
                options.DefaultEntryOptions = new DistributedCacheEntryOptions();
            }

            options.DefaultEntryOptions.AbsoluteExpiration = absoluteExpiration;

            return(options);
        }
コード例 #4
0
 public static SimpleCacheOptions <TKey, TValue> WithValueFactory <TKey, TValue>(
     this SimpleCacheOptions <TKey, TValue> options, Func <TKey, Task <TValue?> > valueFactory) where TValue : class
 {
     return(options
            .WithValueFactory((key, provider, token) => valueFactory(key)));
 }
コード例 #5
0
        public static SimpleCacheOptions <TKey, TValue> WithAbsoluteExpirationRelativeToNow <TKey, TValue>(this SimpleCacheOptions <TKey, TValue> options, TimeSpan absoluteExpiration) where TValue : class
        {
            if (options.DefaultEntryOptions == null)
            {
                options.DefaultEntryOptions = new DistributedCacheEntryOptions();
            }

            options.DefaultEntryOptions.AbsoluteExpirationRelativeToNow = absoluteExpiration;

            return(options);
        }
コード例 #6
0
        public static SimpleCacheOptions <TKey, TValue> WithDefaultEntryOptions <TKey, TValue>(this SimpleCacheOptions <TKey, TValue> options, DistributedCacheEntryOptions entryOptions) where TValue : class
        {
            options.DefaultEntryOptions = entryOptions;

            return(options);
        }
コード例 #7
0
        public static SimpleCacheOptions <TKey, TValue> WithValueSerializer <TKey, TValue>(this SimpleCacheOptions <TKey, TValue> options, IValueSerializer valueSerializer) where TValue : class
        {
            options.ValueSerializer = valueSerializer;

            return(options);
        }
コード例 #8
0
        public static SimpleCacheOptions <TKey, TValue> WithKeySerializer <TKey, TValue>(this SimpleCacheOptions <TKey, TValue> options, IKeySerializer keySerializer) where TValue : class
        {
            options.KeySerializer = keySerializer;

            return(options);
        }
コード例 #9
0
        public static SimpleCacheOptions <TKey, TValue> WithKeyPrefix <TKey, TValue>(this SimpleCacheOptions <TKey, TValue> options, string keyPrefix) where TValue : class
        {
            options.KeySpace = keyPrefix + ":";

            return(options);
        }