当前位置: 首页>>代码示例>>C#>>正文


C# Cache.Contains方法代码示例

本文整理汇总了C#中Cache.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Contains方法的具体用法?C# Cache.Contains怎么用?C# Cache.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cache的用法示例。


在下文中一共展示了Cache.Contains方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater

		public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
		{
			using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo", null))
			{
				ICachingInstrumentationProvider instrumentationProvider = new NullCachingInstrumentationProvider();

				Cache cache = new Cache(backingStore, instrumentationProvider);

				try
				{
					try
					{
						cache.Add("my", new NonSerializableClass());
						Assert.Fail("Should have thrown exception internally to Cache.Add");
					}
					catch (Exception)
					{
						cache.Add("my", new SerializableClass());
						Assert.IsTrue(cache.Contains("my"));
					}
				}
				finally
				{
					backingStore.Flush();
				}
			}
		}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:27,代码来源:CacheExceptionHandlingFixture.cs

示例2: Cache_Remove_Item_Key_Should_Remove_Item

 public void Cache_Remove_Item_Key_Should_Remove_Item()
 {
     Cache<string, int> cache = new Cache<string, int>();
     bool EXPECTED = true;
     cache.Add("1", 1);
     Assert.AreEqual(EXPECTED, cache.Remove("1"));
     int EXPECTEDCOUNT = 0;
     Assert.AreEqual(EXPECTEDCOUNT, cache.Count);
     EXPECTED = false;
     Assert.AreEqual(EXPECTED, cache.Contains("1"));
 }
开发者ID:rahilkidwai,项目名称:Net.Utility,代码行数:11,代码来源:CacheTests.cs

示例3: Contains_ValueIsReferenceType_ChecksForReferenceEquality

        public void Contains_ValueIsReferenceType_ChecksForReferenceEquality()
        {
            ICache<string, SampleValue> cache = new Cache<string, SampleValue>(_timerInterval);
            SampleValue value = new SampleValue();
            ICacheItem<SampleValue> cacheItem = new NonExpiringCacheItem<SampleValue>(value);
            KeyValuePair<string, SampleValue> keyValuePair = new KeyValuePair<string, SampleValue>(_key, value);
            cache.Add(_key, cacheItem);

            bool result = cache.Contains(keyValuePair);

            Assert.True(result);
        }
开发者ID:uhaciogullari,项目名称:MemoryCacheT,代码行数:12,代码来源:ContainsTests.cs

示例4: ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely

		public void ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely()
		{
			MockBackingStore backingStore = new MockBackingStore();
			ICachingInstrumentationProvider instrumentationProvider = new NullCachingInstrumentationProvider();

			Cache cache = new Cache(backingStore, instrumentationProvider);

            try
			{
				cache.Add("foo", "bar");
				Assert.Fail("Should have thrown exception thrown internally to Cache.Add");
			}
			catch (Exception)
			{
				Assert.IsFalse(cache.Contains("foo"));
				Assert.AreEqual(1, backingStore.removalCount);
			}
		}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:18,代码来源:CacheExceptionHandlingFixture.cs

示例5: ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely

        public void ExceptionThrownDuringAddResultsInObjectBeingRemovedFromCacheCompletely()
        {
            TestConfigurationContext context = new TestConfigurationContext();
            MockBackingStore backingStore = new MockBackingStore();
            CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", new CachingConfigurationView(context));

            Cache cache = new Cache(backingStore, scavengingPolicy);
            cache.Initialize(this);

            try
            {
                cache.Add("foo", "bar");
                Assert.Fail("Should have thrown exception thrown internally to Cache.Add");
            }
            catch (Exception)
            {
                Assert.IsFalse(cache.Contains("foo"));
                Assert.AreEqual(1, backingStore.removalCount);
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:20,代码来源:CacheExceptionHandlingFixture.cs

示例6: ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater

        public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
        {
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo", null))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy(10);
                CachingInstrumentationProvider instrumentationProvider = new CachingInstrumentationProvider();

                Cache cache = new Cache(backingStore, scavengingPolicy, instrumentationProvider);
                cache.Initialize(this);

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    cache.Add("my", new SerializableClass());
                    Assert.IsTrue(cache.Contains("my"));
                }
            }
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:22,代码来源:CacheExceptionHandlingFixture.cs

示例7: ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater

        public void ExceptionThrownDuringAddIntoIsolatedStorageAllowsItemToBeReaddedLater()
        {
            TestConfigurationContext context = new TestConfigurationContext();
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo"))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy("test", new CachingConfigurationView(context));

                Cache cache = new Cache(backingStore, scavengingPolicy);
                cache.Initialize(this);

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    cache.Add("my", new SerializableClass());
                    Assert.IsTrue(cache.Contains("my"));
                }
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:22,代码来源:CacheExceptionHandlingFixture.cs

示例8: ItemAddedPreviousToFailedAddIsRemovedCompletelyIfSecondAddFails

        public void ItemAddedPreviousToFailedAddIsRemovedCompletelyIfSecondAddFails()
        {
            using (IsolatedStorageBackingStore backingStore = new IsolatedStorageBackingStore("foo", null))
            {
                CacheCapacityScavengingPolicy scavengingPolicy = new CacheCapacityScavengingPolicy(10);
                CachingInstrumentationProvider instrumentationProvider = new CachingInstrumentationProvider();

                Cache cache = new Cache(backingStore, scavengingPolicy, instrumentationProvider);
                cache.Initialize(this);

                cache.Add("my", new SerializableClass());

                try
                {
                    cache.Add("my", new NonSerializableClass());
                    Assert.Fail("Should have thrown exception internally to Cache.Add");
                }
                catch (Exception)
                {
                    Assert.IsFalse(cache.Contains("my"));
                    Assert.AreEqual(0, backingStore.Count);

                    Hashtable isolatedStorageContents = backingStore.Load();
                    Assert.AreEqual(0, isolatedStorageContents.Count);
                }
            }
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:27,代码来源:CacheExceptionHandlingFixture.cs

示例9: Cache_Initial_Contains_Should_Return_False

 public void Cache_Initial_Contains_Should_Return_False()
 {
     Cache<string, int> cache = new Cache<string, int>();
     bool EXPECTED = false;
     Assert.AreEqual(EXPECTED, cache.Contains(string.Empty));
 }
开发者ID:rahilkidwai,项目名称:Net.Utility,代码行数:6,代码来源:CacheTests.cs


注:本文中的Cache.Contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。