Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Working with the HTTP CacheDownload: Chilkat .NET Assemblies This C# example demonstrates how it is possible to work with the HTTP cache using the Chilkat.Cache class. Chilkat.Cache cache = new Chilkat.Cache(); // Before doing anything, make sure the you tell the component where // the cache is located. cache.AddRoot("c:/cache1"); string url = "http://www.example-code.com/"; // Determine the cache filename for a given URL: string cacheFilename = cache.GetFilename(url); MessageBox.Show(cacheFilename); // Is this url in our cache? bool inCache = cache.IsCached(url); if (inCache) { MessageBox.Show(url + " is in the cache!"); } // Remove a url from cache. cache.DeleteFromCache(url); inCache = cache.IsCached(url); if (!inCache) { MessageBox.Show(url + " is NOT in the cache!"); } // Add something to the cache manually. string eTag = "v1.0"; // The expire time will be 14 days from now. DateTime expire = DateTime.Now; expire = expire.AddDays(14.0); byte[] bData = System.Text.ASCIIEncoding.ASCII.GetBytes("This is a string"); bool ok = cache.SaveToCache(url,expire,eTag,bData); if (!ok) { MessageBox.Show(cache.LastErrorText); } // Fetch what we just inserted back from cache. byte[] cachedData = cache.FetchFromCache(url); if (cachedData.Length == 0) { // Cache miss. MessageBox.Show(url + " not found in cache!"); } // What is the expiration date of the last resource fetched from cache? MessageBox.Show("Expiration: " + Convert.ToString(cache.LastExpirationFetched)); // What is the etag of the last resource fetched from cache? MessageBox.Show("Etag: " + Convert.ToString(cache.LastEtagFetched)); // Was the last cache hit an expired entry? if (cache.LastHitExpired) { MessageBox.Show(cache.LastResourceFetched + " is expired!"); // Let's delete the expired entry. cache.DeleteFromCache(cache.LastResourceFetched); // Or, we could've done this: cache.DeleteAllExpired(); } // Delete everything in the cache: cache.DeleteAll(); Important: The download for this
example does not contain the ChilkatDotNet2.dll which |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.