version 2.1, 1995/08/14 03:57:12
|
version 2.2, 1995/08/20 06:50:52
|
Line 58 PRIVATE char * HTCacheRoot = NULL;
|
Line 58 PRIVATE char * HTCacheRoot = NULL;
|
PRIVATE HTList * HTCache = NULL; /* List of cached elements */ |
PRIVATE HTList * HTCache = NULL; /* List of cached elements */ |
PRIVATE int HTCacheLimit = CACHE_LIMIT; |
PRIVATE int HTCacheLimit = CACHE_LIMIT; |
|
|
|
|
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
/* CACHE MANAGER */ |
/* GARBAGE COLLECTOR */ |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
|
|
/* |
/* |
Line 141 PRIVATE BOOL reserved_name ARGS1(char *,
|
Line 142 PRIVATE BOOL reserved_name ARGS1(char *,
|
} |
} |
|
|
/* |
/* |
|
** Removes all cache entries in memory |
|
*/ |
|
PUBLIC void HTCache_clearMem NOARGS |
|
{ |
|
HTList *cur=HTCache; |
|
HTCacheItem *pres; |
|
if (cur) { |
|
while ((pres = (HTCacheItem *) HTList_nextObject(cur))) { |
|
FREE(pres->filename); |
|
free(pres); |
|
} |
|
HTList_delete(HTCache); |
|
HTCache = NULL; |
|
} |
|
} |
|
|
|
/* |
|
** Removes all cache entries in memory and on disk |
|
*/ |
|
PUBLIC void HTCache_deleteAll NOARGS |
|
{ |
|
HTList *cur=HTCache; |
|
HTCacheItem * pres; |
|
if (cur) { |
|
while ((pres = (HTCacheItem *) HTList_lastObject(cur))) |
|
HTCache_remove(pres); |
|
HTList_delete(HTCache); |
|
HTCache = NULL; |
|
} |
|
} |
|
|
|
/* ------------------------------------------------------------------------- */ |
|
/* NAMING SCHEME */ |
|
/* ------------------------------------------------------------------------- */ |
|
|
|
/* |
** Map url to cache file name. |
** Map url to cache file name. |
*/ |
*/ |
PRIVATE char * cache_file_name ARGS1(char *, url) |
PRIVATE char * cache_file_name ARGS1(char *, url) |
Line 341 PRIVATE char *HTCache_wwwName ARGS1 (cha
|
Line 378 PRIVATE char *HTCache_wwwName ARGS1 (cha
|
return result; |
return result; |
} |
} |
|
|
|
/* ------------------------------------------------------------------------- */ |
/* |
/* CACHE PARAMETERS */ |
** |
/* ------------------------------------------------------------------------- */ |
** Verifies if a cache object exists for this URL and if so returns a URL |
|
** for the cached object. It does not verify whether the object is valid or |
|
** not, for example it might have been expired. |
|
** |
|
** Returns: file name If OK (must be freed by caller) |
|
** NULL If no cache object found |
|
*/ |
|
PUBLIC char * HTCache_getObject ARGS1(char *, url) |
|
{ |
|
if (url && HTCache_isEnabled()) { |
|
char *fnam = cache_file_name(url); |
|
if (fnam) { |
|
FILE *fp = fopen(fnam, "r"); |
|
if (fp) { |
|
char *url = HTCache_wwwName(fnam); |
|
fclose(fp); |
|
if (CACHE_TRACE) |
|
fprintf(TDEST, "Cache....... Object found `%s\'\n", url); |
|
free(fnam); |
|
return url; |
|
} else |
|
free(fnam); |
|
} |
|
} |
|
return NULL; |
|
} |
|
|
|
|
|
/* |
|
** Removes all cache entries in memory |
|
*/ |
|
PUBLIC void HTCache_clearMem NOARGS |
|
{ |
|
HTList *cur=HTCache; |
|
HTCacheItem *pres; |
|
if (cur) { |
|
while ((pres = (HTCacheItem *) HTList_nextObject(cur))) { |
|
FREE(pres->filename); |
|
free(pres); |
|
} |
|
HTList_delete(HTCache); |
|
HTCache = NULL; |
|
} |
|
} |
|
|
|
/* |
|
** Removes all cache entries in memory and on disk |
|
*/ |
|
PUBLIC void HTCache_deleteAll NOARGS |
|
{ |
|
HTList *cur=HTCache; |
|
HTCacheItem * pres; |
|
if (cur) { |
|
while ((pres = (HTCacheItem *) HTList_lastObject(cur))) |
|
HTCache_remove(pres); |
|
HTList_delete(HTCache); |
|
HTCache = NULL; |
|
} |
|
} |
|
|
|
/* Enable Cache |
/* Enable Cache |
** ------------ |
** ------------ |
Line 470 PUBLIC CONST char * HTCache_getRoot NOAR
|
Line 448 PUBLIC CONST char * HTCache_getRoot NOAR
|
return HTCacheRoot; |
return HTCacheRoot; |
} |
} |
|
|
|
|
/* Free Cache Root |
/* Free Cache Root |
** -------------- |
** -------------- |
** For clean up memory |
** For clean up memory |
Line 481 PUBLIC void HTCache_freeRoot NOARGS
|
Line 458 PUBLIC void HTCache_freeRoot NOARGS
|
} |
} |
|
|
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
|
/* CACHE MANAGER */ |
|
/* ------------------------------------------------------------------------- */ |
|
|
|
/* |
|
** Verifies if a cache object exists for this URL and if so returns a URL |
|
** for the cached object. It does not verify whether the object is valid or |
|
** not, for example it might have expired. |
|
** |
|
** Returns: file name If OK (must be freed by caller) |
|
** NULL If no cache object found |
|
*/ |
|
PUBLIC char * HTCache_getReference ARGS1(char *, url) |
|
{ |
|
if (url && HTCache_isEnabled()) { |
|
char *fnam = cache_file_name(url); |
|
if (fnam) { |
|
FILE *fp = fopen(fnam, "r"); |
|
if (fp) { |
|
char *url = HTCache_wwwName(fnam); |
|
fclose(fp); |
|
if (CACHE_TRACE) |
|
fprintf(TDEST, "Cache....... Object found `%s\'\n", url); |
|
free(fnam); |
|
return url; |
|
} else |
|
free(fnam); |
|
} |
|
} |
|
return NULL; |
|
} |
|
|
|
/* |
|
** This function checks whether a document has expired or not. |
|
** The check is based on the metainformation passed in the anchor object |
|
** The function returns YES or NO. |
|
*/ |
|
PUBLIC BOOL HTCache_isValid ARGS1(HTParentAnchor *, anchor) |
|
{ |
|
time_t cur = time(NULL); |
|
time_t expires = HTAnchor_expires(anchor); |
|
return (expires>0 && cur>0 && expires<cur) ? NO : YES; |
|
} |
|
|
|
/* ------------------------------------------------------------------------- */ |
/* CACHE WRITER STREAM */ |
/* CACHE WRITER STREAM */ |
/* ------------------------------------------------------------------------- */ |
/* ------------------------------------------------------------------------- */ |
|
|
Line 577 PUBLIC HTStream* HTCacheWriter ARGS5(
|
Line 598 PUBLIC HTStream* HTCacheWriter ARGS5(
|
if (CACHE_TRACE) |
if (CACHE_TRACE) |
fprintf(TDEST, "Cache....... Creating file %s\n", fnam); |
fprintf(TDEST, "Cache....... Creating file %s\n", fnam); |
|
|
|
|
/* Set up a cache record */ |
/* Set up a cache record */ |
if ((me->cache = (HTCacheItem *) calloc(sizeof(*me->cache), 1)) == NULL) |
if ((me->cache = (HTCacheItem *) calloc(sizeof(*me->cache), 1)) == NULL) |
outofmem(__FILE__, "Cache"); |
outofmem(__FILE__, "Cache"); |