本文整理汇总了C#中LruCache类的典型用法代码示例。如果您正苦于以下问题:C# LruCache类的具体用法?C# LruCache怎么用?C# LruCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LruCache类属于命名空间,在下文中一共展示了LruCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Add_ItemIsAdded_ItemExistsInCache
public void Add_ItemIsAdded_ItemExistsInCache()
{
var lru = new LruCache<string, string>(1);
lru.Add("k1", "v1");
Assert.IsTrue(lru.ContainsKey("k1"));
}
示例2: LruCache_Get
public void LruCache_Get()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.IsNotNull(cache.Get(1));
Assert.IsNotNull(cache.Get(2));
}
示例3: LruCache_Clear
public void LruCache_Clear()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.AreEqual(2, cache.Count);
cache.Clear();
Assert.AreEqual(0, cache.Count);
}
示例4: LruCache_Contains
public void LruCache_Contains()
{
LruCache<int, string> cache = new LruCache<int, string>(2);
cache.Put(1, "One");
cache.Put(2, "Two");
Assert.IsTrue(cache.Contains(1));
Assert.IsTrue(cache.Contains(2));
Assert.IsFalse(cache.Contains(3));
}
示例5: 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;
}
示例6: QueueSystem
private QueueSystem()
{
_howToDownload = new Dictionary<string, Func<Tile, Task<Tile>>>();
_tilesBuffer = new QueueBuffer();
_memoryCache = new LruCache<string, byte[]>(1000);
_storageCache = new Dictionary<string, IOfflineStorage>();
_executantPool = new ExecutantPool(6);
RetryMaxCount = 5;
_executantPool.DownloadImageCompleted += _executantPool_DownloadImageCompleted;
}
示例7: FilesController
public FilesController(IElevationDataStorage elevationDataStorage,
IHttpGatewayFactory httpGatewayFactory,
IDataContainerConverterService dataContainerConverterService,
LruCache<string, TokenAndSecret> cache)
{
_elevationDataStorage = elevationDataStorage;
_httpGatewayFactory = httpGatewayFactory;
_dataContainerConverterService = dataContainerConverterService;
_cache = cache;
}
示例8: 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"));
}
示例9: Complex
public void Complex()
{
var sut = new LruCache(3);
var pages = new[] { 0, 1, 2, 3, 2, 3, 0, 4, 5, 2, 3, 1, 4, 3, 2, 6, 3, 2, 1, 2 };
foreach (var page in pages)
sut.AddPage(page);
var result = sut.Pages;
CollectionAssert.AreEqual(new[] { 2, 1, 3 }, result);
Assert.AreEqual(14, sut.PageFaults);
}
示例10: TestSizeIsLimited
public void TestSizeIsLimited()
{
var cache = new LruCache<string, int>(10);
for (int i = 0; i < 20; i++) {
cache[i.ToString()] = i;
}
Assert.AreEqual(10, cache.Count);
for (int i = 10; i < 20; i++) {
Assert.IsTrue(cache.ContainsKey(i.ToString()));
}
}
示例11: TestLookup
public void TestLookup()
{
var cache = new LruCache<int, string>(10);
cache.InsertOrUpdate(1, "test");
cache.InsertOrUpdate(2, "test");
string retrieved;
Assert.IsTrue(cache.TryLookup(1, out retrieved));
Assert.AreEqual("test", retrieved);
Assert.IsTrue(cache.TryLookup(2, out retrieved));
Assert.AreEqual("test", retrieved);
Assert.IsFalse(cache.TryLookup(3, out retrieved));
}
示例12: OsmController
public OsmController(IHttpGatewayFactory httpGatewayFactory,
IDataContainerConverterService dataContainerConverterService,
ICoordinatesConverter coordinatesConverter,
IGpxSplitterService gpxSplitterService,
IElasticSearchGateway elasticSearchGateway,
LruCache<string, TokenAndSecret> cache)
{
_httpGatewayFactory = httpGatewayFactory;
_dataContainerConverterService = dataContainerConverterService;
_coordinatesConverter = coordinatesConverter;
_gpxSplitterService = gpxSplitterService;
_cache = cache;
_elasticSearchGateway = elasticSearchGateway;
}
示例13: 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();
}
}
示例14: 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");
}
示例15: CacheAccessShouldBumpItToTheFront
public void CacheAccessShouldBumpItToTheFront()
{
var cache = new LruCache<int, int>(3);
cache[1] = 1;
cache[2] = 2;
cache[3] = 3;
var a = cache[1];
cache[4] = 4;
Assert.AreEqual(cache[1], 1);
Assert.AreEqual(cache[3], 3);
Assert.AreEqual(cache[4], 4);
Assert.IsFalse(cache.ContainsKey(2));
}