PowerBuilder
PowerBuilder
Fetch Web Pages from Local Cache
See more HTTP Examples
Demonstrates how to keep a local cache to avoid re-fetching web pages.Chilkat PowerBuilder Downloads
integer li_rc
oleobject loo_Http
string ls_Html
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
// Define a cache directory and set the number of levels based on the anticipated size of the cache.
loo_Http.AddCacheRoot("c:/example/httpCache/")
// up to 256 sub-directories under the cache root will be created as needed to hold cached GET's.
loo_Http.NumCacheLevels = 1
// Tell the http object to fetch from the cache if possible.
loo_Http.FetchFromCache = 1
// Also tell the http object to update the cache with newly fetched pages.
loo_Http.UpdateCache = 1
// This HTTP GET should result in a cache file getting created.
ls_Html = loo_Http.QuickGetStr("https://www.google.com/")
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
return
end if
// The 1st GET was not from cache:
Write-Debug "Fetched from cache: " + string(loo_Http.LastFromCache)
// Fetching again will cause the page to be delivered from our local cache.
ls_Html = loo_Http.QuickGetStr("https://www.google.com/")
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
return
end if
// The 2nd GET is from cache:
Write-Debug "Fetched from cache: " + string(loo_Http.LastFromCache)
destroy loo_Http