Cache Manager and Writing to a File using ANSI C
/*
** (c) COPYRIGHT MIT 1995.
** Please first read the full copyright statement in the file COPYRIGH.
*/
It is useful to have both FWriter and Writer for environments in which
fdopen()
doesn't exist for example. The module contains
the following parts:
This module is implemented by HTFWrite.c,
and it is a part of the
Library of Common Code.
#ifndef HTFWRITE_H
#define HTFWRITE_H
#include "HTStream.h"
#include "HTFormat.h"
This stream simply absorbs data without doing anything what so ever.
extern HTStream * HTBlackHole NOPARAMS;
This function puts up a new stream given an open file descripter. If the file
is not to be closed afterwards, then set leave_open = NO.
extern HTStream * HTFWriter_new PARAMS((FILE * fp,
BOOL leave_open));
Converters
HTSaveAndCallBack
will save to a cache file and call the
request->callback function with the filename as parameter. The
destination for temporary files can be managed by the following
functions:
extern BOOL HTTmp_setRoot PARAMS((CONST char * tmp_root));
extern CONST char * HTTmp_getRoot NOPARAMS;
extern void HTTmp_freeRoot NOPARAMS;
The HTTmp_freeRoot
is called by the HTLibTerminate function
#ifndef pyramid
extern HTConverter HTSaveAndExecute, HTSaveLocally, HTSaveAndCallBack,
HTThroughLine;
#endif
Stream for writing to cache
Note that HTSaveAndCallBack will also generate a cache file.
#ifndef pyramid
extern HTConverter HTCacheWriter;
#endif
The cache contains details of temporary disk files which contain the
contents of remote documents. There is also a list of cache items for each URL in its
anchor object.
An item in the cache
This will not be public in the next release so DON'T USE IT ;-)
typedef struct _HTCacheItem {
HTParentAnchor * anchor;
HTFormat format; /* May have many formats per anchor */
char * filename;
time_t load_time;
time_t load_delay;
int reference_count;
} HTCacheItem;
The Cache Limit
The cache limit is the number of files which are kept. Yes, I know,
the amount of disk space wouldbe more relevant. So this may change.
Currently it is preset to 100 but may be changed by the application by
writing into this variable.
extern int HTCacheLimit;
Enable Cache
If cache_root is NULL then reuse old value or use
HT_CACHE_ROOT
. An empty string will make '/' as cache
root.
extern BOOL HTCache_enable PARAMS((CONST char * cache_root));
Disable Cache
Turns off the cache. Note that the cache can be disabled and enabled
at any time. The cache root is kept and can be reused during the
execution.
extern BOOL HTCache_disable NOPARAMS;
Is Cache Enabled
Returns YES or NO. Also makes sure that we have a root value (even
though it might be invalid)
extern BOOL HTCache_isEnabled NOPARAMS;
Set Cache Root
If cache_root is NULL then the current value (might be a define)
Should we check if the cache_root is actually OK? I think not!
extern BOOL HTCache_setRoot PARAMS((CONST char * cache_root));
Get Cache Root
extern CONST char *HTCache_getRoot NOPARAMS;
For clean up memory
This is done by the Library function HTLibTerminate()
extern void HTCache_freeRoot NOPARAMS;
Clear a cache
Can clear a list of cache items.
extern void HTCacheClear PARAMS((HTList * cache));
To remove All cache files known to this session
extern void HTCacheDeleteAll NOPARAMS;
#endif
End of definition module