• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# LruCache类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中LruCache的典型用法代码示例。如果您正苦于以下问题:C# LruCache类的具体用法?C# LruCache怎么用?C# LruCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LruCache类属于命名空间,在下文中一共展示了LruCache类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:7,代码来源:LruCacheTests.cs


示例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));
 }
开发者ID:ralf-lindberg-3bits,项目名称:blackbox,代码行数:8,代码来源:LruCacheTests.cs


示例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);
 }
开发者ID:ralf-lindberg-3bits,项目名称:blackbox,代码行数:9,代码来源:LruCacheTests.cs


示例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));
 }
开发者ID:ralf-lindberg-3bits,项目名称:blackbox,代码行数:9,代码来源:LruCacheTests.cs


示例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;
 }
开发者ID:jjnguy,项目名称:LRU.Net,代码行数:9,代码来源:UnitTest1.cs


示例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;
 }
开发者ID:SuperMap,项目名称:iClient-for-Win8,代码行数:10,代码来源:QueueSystem.cs


示例7: FilesController

 public FilesController(IElevationDataStorage elevationDataStorage,
     IHttpGatewayFactory httpGatewayFactory, 
     IDataContainerConverterService dataContainerConverterService,
     LruCache<string, TokenAndSecret> cache)
 {
     _elevationDataStorage = elevationDataStorage;
     _httpGatewayFactory = httpGatewayFactory;
     _dataContainerConverterService = dataContainerConverterService;
     _cache = cache;
 }
开发者ID:IsraelHikingMap,项目名称:Site,代码行数:10,代码来源:FilesController.cs


示例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"));
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:12,代码来源:LruCacheTests.cs


示例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);
        }
开发者ID:njmube,项目名称:public,代码行数:12,代码来源:LruCacheTests.cs


示例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()));
            }
        }
开发者ID:purplecow,项目名称:media-library,代码行数:13,代码来源:TestCache.cs


示例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));
        }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:14,代码来源:GenericLruCacheTests.cs


示例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;
 }
开发者ID:IsraelHikingMap,项目名称:Site,代码行数:14,代码来源:OsmController.cs


示例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();
     }
 }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:14,代码来源:LruCacheTests.cs


示例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");
 }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:14,代码来源:LruCacheTests.cs


示例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));
        }
开发者ID:purplecow,项目名称:media-library,代码行数:16,代码来源:TestCache.cs


示例16: TestLruCacheTryGetValue

        public void TestLruCacheTryGetValue()
        {
            RegionEndpoint regionEndpoint;
            var lru = new LruCache<string, RegionEndpoint>(5);

            lru.AddOrUpdate("my-bucket-us-east-1", RegionEndpoint.USEast1);
            lru.AddOrUpdate("my-bucket-us-west-2", RegionEndpoint.USWest2);
            lru.AddOrUpdate("my-bucket-ap-northeast-2", RegionEndpoint.APNortheast2);
            lru.AddOrUpdate("my-bucket-sa-east-1", RegionEndpoint.SAEast1);

            lru.TryGetValue("my-bucket-us-west-2", out regionEndpoint);
            Assert.AreEqual(RegionEndpoint.USWest2, regionEndpoint);

            lru.TryGetValue("my-bucket-ap-northeast-2", out regionEndpoint);
            Assert.AreEqual(RegionEndpoint.APNortheast2, regionEndpoint);
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:16,代码来源:LruCacheTest.cs


示例17: 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);
        }
开发者ID:youkebing,项目名称:dotnet-lru-cache,代码行数:17,代码来源:LruCacheTests.cs


示例18: LruCache_LeastUsedObjectIsRemovedWhenCapacityIsReached

 public void LruCache_LeastUsedObjectIsRemovedWhenCapacityIsReached()
 {
     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));
     Assert.AreEqual(2, cache.Count);
     cache.Put(3, "Three");
     Assert.AreEqual(2, cache.Count);
     Assert.IsNull(cache.Get(1));
     Assert.IsNotNull(cache.Get(2));
     Assert.IsNotNull(cache.Get(3));
     cache.Put(4, "Four");
     Assert.AreEqual(2, cache.Count);
     Assert.IsNull(cache.Get(2));
     Assert.IsNotNull(cache.Get(3));
     Assert.IsNotNull(cache.Get(4));
 }
开发者ID:ralf-lindberg-3bits,项目名称:blackbox,代码行数:19,代码来源:LruCacheTests.cs


示例19: LruCache

 public void GetとPutがスレッドセーフである()
 {
     LruCache lruCache = new LruCache(5, 1);
     Action action1 = () => {
         for (int i = 0; i < 1000 * 1000; i++)
         {
             lruCache.Put("a", "abc");
             Assert.AreEqual("abc", lruCache.Get("a"));
         }
     };
     Action action2 = () => {
         for (int i = 0; i < 1000 * 1000; i++)
         {
             lruCache.Put("a", "abc");
             Assert.AreEqual("abc", lruCache.Get("a"));
         }
     };
     action1.BeginInvoke(null, null);
     action2.BeginInvoke(null, null);
 }
开发者ID:kaorun55,项目名称:TddBootCamp,代码行数:20,代码来源:LruCacheTest.cs


示例20: Database

        /// <summary>
        /// Initializes a new instance of the <see cref="Couchbase.Lite.Database"/> class.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name="manager">Manager.</param>
        internal Database(String path, Manager manager)
        {
            Debug.Assert(System.IO.Path.IsPathRooted(path));

            //path must be absolute
            Path = path;
            Name = FileDirUtils.GetDatabaseNameFromPath(path);
            Manager = manager;
            DocumentCache = new LruCache<string, Document>(MaxDocCacheSize);
            UnsavedRevisionDocumentCache = new Dictionary<string, WeakReference>();
 
            // FIXME: Not portable to WinRT/WP8.
            ActiveReplicators = new List<Replication>();
            AllReplicators = new List<Replication> ();

            _changesToNotify = new AList<DocumentChange>();

            StartTime = DateTime.UtcNow.ToMillisecondsSinceEpoch ();

            MaxRevTreeDepth = DefaultMaxRevs;
        }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:26,代码来源:Database.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Lua类代码示例发布时间:2022-05-24
下一篇:
C# LowLevelMouseProc类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap