コード例 #1
0
        public void Add_Two_Test_Call_remove()
        {
            var called = false;

            _metadataProvider.Expect(x => x.GetEarliestAccessedItem("d")).Return(new CacheItemMetadata
            {
                Domain = "d",
                Size   = 5
            });
            _mockRepository.ReplayAll();

            var manager = new CacheStoreQuotaManager(_metadataProvider, i => called = true, _settings);

            manager.ItemAdded(new CacheItemMetadata {
                Domain = "d", Size = 5
            });
            manager.ItemAdded(new CacheItemMetadata {
                Domain = "d", Size = 6
            });
            Thread.Sleep(1000);

            Assert.AreEqual(true, called);
            Assert.AreEqual(6, manager.GrandTotal);
            Assert.AreEqual(1, manager.StorageMetadata.Count);
        }
コード例 #2
0
        public void Add_Test_GrandTotal_remove()
        {
            bool called = false;

            _metadataProvider.Expect(x => x.GetEarliestAccessedItem()).Return(new CacheItemMetadata()
            {
                Domain = "c",
                Size   = 3
            });
            _mockRepository.ReplayAll();

            var manager = new CacheStoreQuotaManager(_metadataProvider, (i) => called = true, _settings);

            manager.ItemAdded(new CacheItemMetadata()
            {
                Domain = "a", Size = 9
            });
            manager.ItemAdded(new CacheItemMetadata()
            {
                Domain = "b", Size = 9
            });
            manager.ItemAdded(new CacheItemMetadata()
            {
                Domain = "c", Size = 3
            });
            Thread.Sleep(1000);

            Assert.AreEqual(true, called);
            Assert.AreEqual(18, manager.GrandTotal);
            Assert.AreEqual(3, manager.StorageMetadata.Count);
        }
コード例 #3
0
        public void Add_Test()
        {
            _mockRepository.ReplayAll();
            var manager = new CacheStoreQuotaManager(_metadataProvider, null, _settings);

            manager.ItemAdded(new CacheItemMetadata {
                Domain = "d", Size = 5
            });
            Assert.AreEqual(5, manager.GrandTotal);
            Assert.AreEqual(1, manager.StorageMetadata.Count);
        }
コード例 #4
0
ファイル: FileStore.cs プロジェクト: yyf919/CacheCow
		/// <summary>
		/// 
		/// </summary>
		/// <param name="dataRoot"></param>
		/// <param name="bufferedFileAccess">It first loads the response into a memory buffer before processing. 
		/// Improves file locking especially if response takes long time to come back from server.
		/// </param>
		private FileStore(string dataRoot, bool bufferedFileAccess)
		{
			_bufferedFileAccess = bufferedFileAccess;
			_dataRoot = dataRoot;
			if (!Directory.Exists(dataRoot))
				Directory.CreateDirectory(dataRoot);

			_dbFileName = Path.Combine(dataRoot, CacheMetadataDbName);
			if (!File.Exists(_dbFileName))
				BuildDb(_dbFileName);

			_database = Database.OpenFile(_dbFileName);
			_quotaManager = new CacheStoreQuotaManager(this, RemoveWithoutTellingQuotaManager);
		}
コード例 #5
0
        public void Add_Two_Test_NotRemove()
        {
            var called = false;

            _mockRepository.ReplayAll();
            var manager = new CacheStoreQuotaManager(_metadataProvider, i => called = true, _settings);

            manager.ItemAdded(new CacheItemMetadata {
                Domain = "d", Size = 5
            });
            manager.ItemAdded(new CacheItemMetadata {
                Domain = "d", Size = 5
            });
            Assert.AreEqual(false, called);
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataRoot"></param>
        /// <param name="bufferedFileAccess">It first loads the response into a memory buffer before processing.
        /// Improves file locking especially if response takes long time to come back from server.
        /// </param>
        private FileStore(string dataRoot, bool bufferedFileAccess)
        {
            _bufferedFileAccess = bufferedFileAccess;
            _dataRoot           = dataRoot;
            if (!Directory.Exists(dataRoot))
            {
                Directory.CreateDirectory(dataRoot);
            }

            _dbFileName = Path.Combine(dataRoot, CacheMetadataDbName);
            if (!File.Exists(_dbFileName))
            {
                BuildDb(_dbFileName);
            }

            _database     = Database.OpenFile(_dbFileName);
            _quotaManager = new CacheStoreQuotaManager(this, RemoveWithoutTellingQuotaManager);
        }