本文整理汇总了C#中CacheStorage.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# CacheStorage.Contains方法的具体用法?C# CacheStorage.Contains怎么用?C# CacheStorage.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CacheStorage
的用法示例。
在下文中一共展示了CacheStorage.Contains方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemStaysInCacheWhenExpiringEventIsCanceled
public void ItemStaysInCacheWhenExpiringEventIsCanceled()
{
var key = "1";
var value = 1;
var cache = new CacheStorage<string, int>();
cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
cache.Expiring += (sender, e) =>
{
e.Cancel = true;
};
cache.Add(key, value, expiration: new TimeSpan(0, 0, 0, 0, 250));
ThreadHelper.Sleep(750);
Assert.IsTrue(cache.Contains(key));
}
示例2: AutomaticallyRemovesExpiredItems
public void AutomaticallyRemovesExpiredItems()
{
var cache = new CacheStorage<string, int>();
cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
cache.Add("1", 1, expiration: new TimeSpan(0, 0, 0, 0, 250));
Assert.IsTrue(cache.Contains("1"));
ThreadHelper.Sleep(750);
Assert.IsFalse(cache.Contains("1"));
}
示例3: AutomaticallyRemovesExpiredItemsOfACacheStorageWithDefaultExpirationPolicyInitializationCode
public void AutomaticallyRemovesExpiredItemsOfACacheStorageWithDefaultExpirationPolicyInitializationCode()
{
var cache = new CacheStorage<string, int>(() => ExpirationPolicy.Duration(TimeSpan.FromMilliseconds(250)));
cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
cache.Add("1", 1);
Assert.IsTrue(cache.Contains("1"));
ThreadHelper.Sleep(750);
Assert.IsFalse(cache.Contains("1"));
}
示例4: RemovesExistingValue
public void RemovesExistingValue()
{
var cache = new CacheStorage<string, int>();
cache.Add("1", 1);
Assert.IsTrue(cache.Contains("1"));
cache.Remove("1");
Assert.IsFalse(cache.Contains("1"));
}
示例5: IsAutomaticallyEnabledWhenStartedDisabledButAddingItemWithCustomExpirationPolicy
public void IsAutomaticallyEnabledWhenStartedDisabledButAddingItemWithCustomExpirationPolicy()
{
var cache = new CacheStorage<string, int>();
cache.ExpirationTimerInterval = TimeSpan.FromMilliseconds(250);
cache.Add("1", 1, expiration: new TimeSpan(0, 0, 0, 0, 250));
Assert.IsTrue(cache.Contains("1"));
ThreadHelper.Sleep(750);
Assert.IsFalse(cache.Contains("1"));
}
示例6: AddsItemToCacheWithOverrideAndReturnsIt
public void AddsItemToCacheWithOverrideAndReturnsIt()
{
var cache = new CacheStorage<string, int>();
cache.Add("1", 1);
var value = cache.GetFromCacheOrFetch("1", () => 2, true);
Assert.IsTrue(cache.Contains("1"));
Assert.AreEqual(2, cache["1"]);
Assert.AreEqual(2, value);
}
示例7: ReturnsCachedItem
public void ReturnsCachedItem()
{
var cache = new CacheStorage<string, int>();
cache.Add("1", 1);
var value = cache.GetFromCacheOrFetch("1", () => 2);
Assert.IsTrue(cache.Contains("1"));
Assert.AreEqual(1, cache["1"]);
Assert.AreEqual(1, value);
}
示例8: ReturnsTrueForExistingKey
public void ReturnsTrueForExistingKey()
{
var cache = new CacheStorage<string, int>();
cache.Add("1", 1);
cache.Add("2", 2);
Assert.IsTrue(cache.Contains("2"));
}
示例9: ThrowsArgumentNullExceptionForNullKey
public void ThrowsArgumentNullExceptionForNullKey()
{
var cache = new CacheStorage<string, int>();
ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => cache.Contains(null));
}
示例10: AutomaticallyRemovesExpiredItems
public void AutomaticallyRemovesExpiredItems()
{
var cache = new CacheStorage<string, int>();
cache.Add("1", 1, expiration: new TimeSpan(0, 0, 1));
Assert.IsTrue(cache.Contains("1"));
ThreadHelper.Sleep(1500);
Assert.IsFalse(cache.Contains("1"));
}