コード例 #1
0
        public Cache(
            CacheOptions options,
            Func <TKey, Task <TValue> > loaderFunction)
        {
            this.SetOptions(options);

            LoaderFunction = loaderFunction;
            _keyGates      = new ConcurrentDictionary <TKey, KeyGate <TKey> >();
            _kvStore       = new InMemoryKeyValueStore <TKey, CacheEntry <TValue> >();
            this.InitializeFlushTimer();
        }
コード例 #2
0
        public Cache(
            IEqualityComparer <TKey> comparer,
            CacheOptions options,
            Func <TKey, Task <TValue> > loaderFunction)
            : this(options, loaderFunction)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException(nameof(comparer));
            }

            _keyGates = new ConcurrentDictionary <TKey, KeyGate <TKey> >();
            _kvStore  = new InMemoryKeyValueStore <TKey, CacheEntry <TValue> >(comparer);
            this.InitializeFlushTimer();
        }
コード例 #3
0
        private void SetOptions(CacheOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _cacheName = options.CacheName;

            if (_cacheName == null)
            {
                throw new ArgumentNullException(nameof(options.CacheName));
            }
            if (_cacheName.Trim() == string.Empty)
            {
                throw new ArgumentException(nameof(options.CacheName) + " may not be blank or white space");
            }

            options.Initialize();
            _options = options;
        }
コード例 #4
0
 public Cache(
     IEqualityComparer <TKey> comparer,
     CacheOptions options)
     : this(comparer, options, null)
 {
 }
コード例 #5
0
 public Cache(
     CacheOptions options)
     : this(options, null)
 {
 }