当前位置: 首页>>代码示例>>C#>>正文


C# Cache.Count方法代码示例

本文整理汇总了C#中Cache.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Cache.Count方法的具体用法?C# Cache.Count怎么用?C# Cache.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cache的用法示例。


在下文中一共展示了Cache.Count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

 //This is a basic example of how to use the crawler
 //In case of a cache miss, it prints out the page's title and
 //absolute URI, and saves the page data to the filesystem.
 public static void Main(String[] args)
 {
     if ((args.Length == 2 || args.Length == 3) &&
         Uri.IsWellFormedUriString(args[0], UriKind.Absolute))
     {
         Uri startingUri = new Uri(args[0]);
         String targetDirectoryPath = args[1];
         bool followExternal =
             args.Length == 3 && args[2] == "--follow-external";
         Console.WriteLine("Loading from cache...");
         Cache cache = new Cache(startingUri, targetDirectoryPath);
         Console.WriteLine(
             "Cache loaded - {0} pages stored in cache", cache.Count());
         Crawler crawler = new Crawler(cache, followExternal);
         Persister persister = new Persister(targetDirectoryPath, startingUri);
         //This event is fired when the crawler's process is over
         crawler.WorkComplete += () =>
         {
             Environment.Exit(0);
         };
         //This event is fired every time a valid page is downloaded
         crawler.NewPageFetched += (page) =>
         {
             Console.WriteLine(page.Title + " - " + page.Uri.AbsoluteUri);
             persister.Save(page);
         };
         //starts the crawler, on a different thread
         crawler.Crawl(startingUri);
         Console.WriteLine("Crawler started, press CTRL+C to interrupt");
         while (true) { }
     }
     else
     {
         Console.WriteLine("Crawler");
         Console.WriteLine("Usage:");
         Console.WriteLine(
             "Tenteikura.Example.exe <starting_uri> <target_directory> [--options]");
         Console.WriteLine(
             "<starting_uri> : a valid absolute URL which will be the starting point for the crawler");
         Console.WriteLine(
             "<target_directory> : the directory where the page files will be saved");
         Console.WriteLine("");
         Console.WriteLine("OPTIONS:");
         Console.WriteLine(
             "The only option available is --follow-external, which will make the crawler fetch non-local urls as well");
         Console.WriteLine("EXAMPLE: ");
         Console.WriteLine(
             @"Tenteikura.Example.exe http://telenor.com C:\mytargetdirectory --follow-external");
     }
 }
开发者ID:bolthar,项目名称:tenteikura,代码行数:53,代码来源:Program.cs

示例2: Count_ShouldGiveProperResults_Test

        public void Count_ShouldGiveProperResults_Test()
        {
            Cache cache = new Cache();

            Assert.AreEqual(0, cache.Count());
            cache.Add(TestKey, TestValue, new TimeSpan(0, 5, 0));
            Assert.AreEqual(1, cache.Count());
            cache.Add(TestKey, TestValue, new TimeSpan(0, 5, 0));
            Assert.AreEqual(1, cache.Count());
            cache.Add("otherKey", TestValue, new TimeSpan(0, 5, 0));
            Assert.AreEqual(2, cache.Count());
        }
开发者ID:RejectKid,项目名称:RiotSharp,代码行数:12,代码来源:CacheTest.cs


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