本文整理汇总了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");
}
}
示例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());
}