Re: Cache problem + fix

jose.kahan@w3.org wrote:
> 
> Problem:
> 
> If the libwww cache contains an entry for a document and you PUT the
> document corresponding to this entry, the entry isn't updated. If you
> quit the libwww application and you browse the document, you'll get the
> previous version.
> 
> Fix:
> 
> In HTCache.c, I systematically delete the cache entry whenever doing
> a PUT:

Hmm, that is what the HTCacheCheckFilter() should do in HTCache.c (it is
only done when we have a 2xx code so that we don't delete the cached
entry if the operation doesn't suceed).  

PRIVATE int HTCacheCheckFilter (HTRequest * request, HTResponse *
response,
				void * param, int status)
{
    if (status/100==2 && !HTMethod_isSafe(HTRequest_method(request))) {
        if (status==201) {
	    HTParentAnchor * anchor =
HTAnchor_parent(HTResponse_redirection(response));
    	    if (!anchor) anchor = HTRequest_anchor(request);
	    HTCache_touch(request, response, anchor);
	} else {
	    HTParentAnchor * anchor = HTRequest_anchor(request);
	    HTCache * cache = HTCache_find(anchor);
	    if (cache) {
		if (status == 204)
		    HTCache_updateMeta(cache, request, response);
		else
		    HTCache_remove(cache);
	    }
	    HTCache_touch(request, response, anchor);
	}
    }
    return HT_OK;
}

After the 204 status code is used slightly different now, the check
should also be updated - try this patch to see if it works better:

Index: HTCache.c
===================================================================
RCS file: /sources/public/libwww/Library/src/HTCache.c,v
retrieving revision 2.66
diff -c -r2.66 HTCache.c
*** HTCache.c	1999/03/14 02:01:08	2.66
--- HTCache.c	1999/06/22 20:47:23
***************
*** 1366,1374 ****
  	    HTParentAnchor * anchor = HTRequest_anchor(request);
  	    HTCache * cache = HTCache_find(anchor);
  	    if (cache) {
! 		if (status == 204)
  		    HTCache_updateMeta(cache, request, response);
! 		else
  		    HTCache_remove(cache);
  	    }
  	    HTCache_touch(request, response, anchor);
--- 1366,1381 ----
  	    HTParentAnchor * anchor = HTRequest_anchor(request);
  	    HTCache * cache = HTCache_find(anchor);
  	    if (cache) {
! 		/* 
! 		** If we recieve a 204 and the method is unsafe then we have
! 		** to delete the cache body but not the header information
! 		*/
! 		if (status == 204) {
  		    HTCache_updateMeta(cache, request, response);
! 		    cache->size = 0;
! 		    cache->range = YES;
! 		    REMOVE(cache->cachename);
! 		} else
  		    HTCache_remove(cache);
  	    }
  	    HTCache_touch(request, response, anchor);

-- 
Henrik Frystyk Nielsen, <frystyk@w3.org>
World Wide Web Consortium, MIT/LCS NE43-356
545 Technology Square, Cambridge MA 02139, USA

Received on Tuesday, 22 June 1999 16:49:32 UTC