Beispiel #1
0
        public UnboundedCache(string name, IUnboundedStorage <TKey, TValue> dataStorage, long maxFlushMemorySize, long maxCacheMemorySize, Func <TValue, long> sizeEstimator)
        {
            this._name = name;
            this.MaxFlushMemorySize = maxFlushMemorySize;

            this.flushPending     = new ConcurrentDictionary <TKey, WriteValue <TValue> >();
            this.flushPendingLock = new ReaderWriterLockSlim();
            this.flushPendingSize = 0;
            this.flushRates       = new List <float>();
            this.flushRatesLock   = new ReaderWriterLockSlim();

            this.memoryCache        = new MemoryCache <TKey, TValue>(name, maxCacheMemorySize, sizeEstimator);
            this.MaxCacheMemorySize = maxCacheMemorySize;

            this.dataStorage   = dataStorage;
            this.sizeEstimator = sizeEstimator;

            this.storageWorker     = new Worker("UnboundedCache.{0}.StorageWorker".Format2(name), StorageWorker, true, TimeSpan.FromMilliseconds(0), TimeSpan.FromSeconds(60));
            this.storageBlockEvent = new ManualResetEventSlim(true);

            this.shutdownToken = new CancellationTokenSource();

            // start storage thread, responsible for flushing out blocks
            this.storageWorker.Start();
        }
Beispiel #2
0
 public UnboundedCache(string name, IUnboundedStorage <TKey, TValue> dataStorage)
 {
     this.name        = name;
     this.dataStorage = dataStorage;
     this.missingData = new ConcurrentSetBuilder <TKey>();
 }