W3C home > Mailing lists > Public > www-lib@w3.org > July to September 1999

Persistant Cache

From: <chris@cousteau.gso.uri.edu>
Date: Wed, 28 Jul 1999 23:01:55 -0400 (EDT)
To: www-lib@w3.org
Message-ID: <Pine.LNX.4.10.9907282247160.12391-100000@cousteau.gso.uri.edu>
So I guess the cache should be really really easy to implement into a
program, from what I've seen, shouldn't THIS do it?  
This is a simple, useless sample program I have whose only pupose in life
is to try and load something and hopefully fill up the cache a bit.  You
pass it an absolute url and it loads it, after initializing and stuff.
It creates the cache directory, and it seems to succeed in reading the
page off of the web server (my parser my_handler() gets called and passed
the correct token/value pair)  but no data is stored in the cache
The thing is, the cache works fine when I take out the parser my_handler, 
which makes me think I'm messing something up rather basic here,
something conceptual. Perhaps someone could shed some light on this.  
Thanks a bunch!  The code follows.


// Chris Mulhearn,  cb.cc   A quick test of the cache.
#include <iostream.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <assert.h>
#include <errno.h>

#include <sys/socket.h>
#include <sys/types.h>          
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/wait.h>

#include <netinet/in.h>

#include <w3c-libwww/wwwsys.h>
#include <w3c-libwww/WWWLib.h>
#include <w3c-libwww/WWWHTTP.h>
#include <w3c-libwww/WWWInit.h>

int my_handler(HTRequest *request, HTResponse */*response*/, const char *token, const char *val) {
   cerr << "I got called! (this out to stderr) token [" << token << "] value [" << val << "]" << endl;

int main(int argc, char * argv[])
   if(argc != 2) {
      cout << "usage: cb <url>" << endl;
   char * url = new char[strlen(argv[1])];
   char * str = new char[65536];
   strcpy(url, argv[1]);
   // Set up http and cache protocols.
   HTProtocol_add("http", "buffered_tcp", HTTP_PORT, YES, HTLoadHTTP, NULL);
   HTProtocol_add("cache", "local", 0, YES, HTLoadCache, NULL);
   HTList * _conv = HTList_new();
   HTList *transfer_encodings = HTList_new();
   //Setup Cache!
   if(HTCacheInit("file:/devel/CACHE", 20) == YES) { 
      cerr << "Cache initialized!" << endl;

   //   if(HTCacheIndex_write("file:/devel/CACHE") == YES) {
   //      cerr << "Wrote cache index!" << endl;
   //   }
// If I comment out this parser, the cache gets filled.  If not, its
// left totally empty.

   HTHeader_addParser("Content-Length", NO, my_handler);

   // This tries to read the url given as an argument.
   FILE * stream;
   HTRequest *_request = HTRequest_new();
   HTRequest_setOutputFormat(_request, WWW_SOURCE);
   HTRequest_setOutputStream(_request, HTFWriter_new(_request, stream, YES));
   HTRequest_setReloadMode(_request, HT_CACHE_VALIDATE);
   int status = HTLoadAbsolute(url, _request); 
   if(status == YES) {
      cout << "looks good.[stdout]" << endl;
   return 0;
Received on Thursday, 29 July 1999 11:03:49 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:33:51 UTC