(Delphi) Using the Disk Cache 使用磁盘缓存
2014-04-02 09:52
351 查看
The Chilkat Spider component has disk caching capabilities. To setup a disk cache, create a new directory anywhere on your local hard drive and set the CacheDir property to the path. For example, you might create "c:/spiderCache/". The UpdateCache property controls whether downloaded pages are saved to the cache. The FetchFromCache property controls whether the cache is first checked for pages. The LastFromCache property tells whether the last URL fetched came from cache or not.
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, SPIDERXLib_TLB, OleCtrls; ... procedure TForm1.Button1Click(Sender: TObject); var spider: TSpider; i: Integer; success: Integer; begin // The Chilkat Spider component/library is free. spider := TSpider.Create(Self); // Set our cache directory and make sure saving-to-cache and fetching-from-cache // are both turned on: spider.CacheDir := 'c:/spiderCache/'; spider.FetchFromCache := 1; spider.UpdateCache := 1; // If you run this code twice, you'll find that the 2nd run is extremely fast // because the pages will be retrieved from cache. // The spider object crawls a single web site at a time. As you'll see // in later examples, you can collect outbound links and use them to // crawl the web. For now, we'll simply spider 10 pages of chilkatsoft.com spider.Initialize('www.chilkatsoft.com'); // Add the 1st URL: spider.AddUnspidered('http://www.chilkatsoft.com/'); // Begin crawling the site by calling CrawlNext repeatedly. for i := 0 to 9 do begin success := spider.CrawlNext(); if (success = 1) then begin // Show the URL of the page just spidered. Memo1.Lines.Add(spider.LastUrl); // The HTML is available in the LastHtml property end else begin // Did we get an error or are there no more URLs to crawl? if (spider.NumUnspidered = 0) then begin ShowMessage('No more URLs to spider'); end else begin ShowMessage(spider.LastErrorText); end; end; // Sleep 1 second before spidering the next URL. // The reason for waiting a short time before the next fetch is to prevent // undue stress on the web server. However, if the last page was retrieved // from cache, there is no need to pause. if (spider.LastFromCache <> 1) then begin spider.SleepMs(1000); end; end; end;
相关文章推荐
- 使用缓存管理器,尽你之能力(Cache Me if You Can: Using the NT Cache Manager )
- 在通配符中使用范围运算符(Using the Range Operator in Wildcard Queries)
- Your boot partition is on a disk using the GPT partitioning Scheme but this machines cannot boot
- Android Material Design-Using the Material Theme(使用Material主题)-(二)
- 使用游标批量更新/填充数据库(The Using of Cursor)
- DownLoadManager[20530:228829] DiskImageCache: Could not resolve the absolute path of the old directory.
- iOS Mobile Development: Using Xcode Targets to Reuse the Code 使用xcode targets来实现代码复用
- Create RESTful Applications Using The Zend Framework(使用Zend Framework创建一个Restful应用)
- 【转载】10.1\t使用项目视图类(Using the Item View Convenience Classes)
- 使用oracle时一些优化事项(转自:http://www.ij2ee.com/2010/07/22/some-optimization-issues-when-using-the-oracle.html)
- Using the Flex Compilers Flex编译器的使用 第四部分
- 转载:Using PowerShell in the build process 使用Powershell进行build
- Matlab使用技巧:Rapid Code Iteration Using Cells in the Editor
- jsf in action 笔记:在组件中使用EL语言(Using the EL with components)--2008.04.11
- Delphi之使用资源文件(Using Resource Files)
- 使用游标批量更改/填充数据表中的记录值(TheUsingofCursor)
- iphone-使用TextField及关闭键盘(useing TextField for inputs、using the keyboard)
- 【转载】10.1\t使用项目视图类(Using the Item View Convenience Classes)
- 使用cocapods报错 [!] Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes
- 使用MSBUILD 构建时出错 error MSB3086: Task could not find "sgen.exe" using the SdkToolsPath