本文整理汇总了C#中LruCache.Add方法的典型用法代码示例。如果您正苦于以下问题:C# LruCache.Add方法的具体用法?C# LruCache.Add怎么用?C# LruCache.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LruCache
的用法示例。
在下文中一共展示了LruCache.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add_ItemIsAdded_CurrentSizeIncreasesByItemSize
public void Add_ItemIsAdded_CurrentSizeIncreasesByItemSize()
{
var lru = new LruCache<string, string>(1024, 2);
Assert.AreEqual(0, lru.CurrentSize);
lru.Add("k1", "v1");
Assert.AreEqual(2, lru.CurrentSize);
lru.Add("k2", "v2");
Assert.AreEqual(4, lru.CurrentSize);
lru.Add("k3", "v3");
Assert.AreEqual(6, lru.CurrentSize);
lru.Add("k4", "v4");
Assert.AreEqual(8, lru.CurrentSize);
lru.Add("k5", "v5");
}
示例2: Add_DuplicateKeyAdded_ThrowsArgumentException
public void Add_DuplicateKeyAdded_ThrowsArgumentException()
{
try
{
var lru = new LruCache<string, string>(5);
lru.Add("k1", "v1");
lru.Add("k1", "v1");
Assert.Fail("Should not have reached this point");
}
catch (ArgumentException)
{
Assert.Pass();
}
}
示例3: Add_ItemIsAdded_ItemExistsInCache
public void Add_ItemIsAdded_ItemExistsInCache()
{
var lru = new LruCache<string, string>(1);
lru.Add("k1", "v1");
Assert.IsTrue(lru.ContainsKey("k1"));
}
示例4: GetInitializedCache
private static LruCache<string, string> GetInitializedCache(int max, params string[] entries)
{
var cache = new LruCache<string, string>(max);
foreach (var entry in entries)
{
cache.Add(entry, entry);
}
return cache;
}
示例5: Add_MaxSizeIsReached_OldestItemDiscarded
public void Add_MaxSizeIsReached_OldestItemDiscarded()
{
var lru = new LruCache<string, string>(5);
lru.Add("k1", "v1");
lru.Add("k2", "v2");
lru.Add("k3", "v3");
lru.Add("k4", "v4");
lru.Add("k5", "v5");
lru.Add("k6", "v6");
Assert.IsFalse(lru.ContainsKey("k1"));
}
示例6: Add_MaxSizeIsReached_DiscardedCountIncreases
public void Add_MaxSizeIsReached_DiscardedCountIncreases()
{
var lru = new LruCache<string, string>(5);
lru.Add("k1", "v1");
lru.Add("k2", "v2");
lru.Add("k3", "v3");
lru.Add("k4", "v4");
lru.Add("k5", "v5");
Assert.AreEqual(0, lru.DiscardedCount);
lru.Add("k6", "v6");
Assert.AreEqual(1, lru.DiscardedCount);
lru.Add("k7", "v7");
Assert.AreEqual(2, lru.DiscardedCount);
}
示例7: NewestItemKey_CacheNotEmpty_ReturnsNewestKey
public void NewestItemKey_CacheNotEmpty_ReturnsNewestKey()
{
var lru = new LruCache<string, string>(2);
lru.Add("k1", "v1");
lru.Add("k2", "v2");
Assert.AreEqual("k2", lru.NewestKey);
}
示例8: ContainsKey_KeyExists_ReturnsTrue
public void ContainsKey_KeyExists_ReturnsTrue()
{
var lru = new LruCache<string, string>(1);
lru.Add("k1", "v1");
Assert.IsTrue(lru.ContainsKey("k1"));
}
示例9: Resize_NewSizeCausesTrim_OnlyOldestItemsDiscarded
public void Resize_NewSizeCausesTrim_OnlyOldestItemsDiscarded()
{
var lru = new LruCache<string, string>(5);
lru.Add("k1", "v1");
lru.Add("k2", "v2");
lru.Add("k3", "v3");
lru.Add("k4", "v4");
lru.Add("k5", "v5");
lru.Resize(3);
Assert.IsFalse(lru.ContainsKey("k1"));
Assert.IsFalse(lru.ContainsKey("k2"));
Assert.IsTrue(lru.ContainsKey("k3"));
Assert.IsTrue(lru.ContainsKey("k4"));
Assert.IsTrue(lru.ContainsKey("k5"));
}
示例10: Remove_ItemIsRemoved_ReturnsTrue
public void Remove_ItemIsRemoved_ReturnsTrue()
{
var lru = new LruCache<string, string>(1);
lru.Add("k1", "v1");
Assert.IsTrue(lru.Remove("k1"));
}
示例11: Remove_KeyDoesNotExist_ReturnsFalse
public void Remove_KeyDoesNotExist_ReturnsFalse()
{
var lru = new LruCache<string, string>(1);
lru.Add("k1", "v1");
Assert.IsFalse(lru.Remove("k2"));
}
示例12: Clear_CacheIsNotEmpty_CurrentSizeIsZero
public void Clear_CacheIsNotEmpty_CurrentSizeIsZero()
{
var lru = new LruCache<string, string>(5);
lru.Add("k1", "v1");
lru.Add("k2", "v2");
lru.Add("k3", "v3");
lru.Add("k4", "v4");
lru.Add("k5", "v5");
Assert.AreEqual(5, lru.CurrentSize);
lru.Clear();
Assert.AreEqual(0, lru.CurrentSize);
}
示例13: Remove_ItemIsRemoved_CurrentSizeDecreasesByItemSize
public void Remove_ItemIsRemoved_CurrentSizeDecreasesByItemSize()
{
var lru = new LruCache<string, string>(5);
lru.Add("k1", "v1");
lru.Add("k2", "v2");
lru.Add("k3", "v3");
lru.Add("k4", "v4");
lru.Add("k5", "v5");
Assert.AreEqual(5, lru.CurrentSize);
lru.Remove("k1");
Assert.AreEqual(4, lru.CurrentSize);
lru.Remove("k2");
Assert.AreEqual(3, lru.CurrentSize);
lru.Remove("k3");
Assert.AreEqual(2, lru.CurrentSize);
lru.Remove("k4");
Assert.AreEqual(1, lru.CurrentSize);
lru.Remove("k5");
Assert.AreEqual(0, lru.CurrentSize);
}
示例14: Contains_EntryExists_ReturnsTrue
public void Contains_EntryExists_ReturnsTrue()
{
var lru = new LruCache<string, string>(1);
lru.Add("k1", "v1");
var entry = new KeyValuePair<string, string>("k1", "v1");
Assert.IsTrue(lru.Contains(entry));
}
示例15: TryGetValue_KeyExists_HitCountIncreased
public void TryGetValue_KeyExists_HitCountIncreased()
{
var lru = new LruCache<string, string>(1);
lru.Add("k1", "v1");
Assert.AreEqual(0, lru.HitCount);
string value;
lru.TryGetValue("k1", out value);
Assert.AreEqual(1, lru.HitCount);
}