本文整理汇总了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();
}
}
}
示例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"));
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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"));
}
}
}
示例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"));
}
}
}
示例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);
}
}
}
示例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));
}