Control-Cache max-age when polipo is restarted
Rubén Ramos <[email protected]>
| Newsgroups | gmane.comp.web.polipo.user |
|---|---|
| Message-ID | <CAE5A9fEBrAPGNhnUaZX3BgLWfafd4H62RAvFF6fb4vhgrZRdSA@mail.gmail.com> |
Hi, I've been using polipo and I've found out with a small issue related with Control-Cache header values. When I received a response with a header which includes max-age value and I keep running polipo, the rest of request works fine. It means, when the max-age is elapsed polipo request the server again refreshing the cache. The problem that I found is when I make different requests and I restart polipo between them. Polipo is not storing the value of max-age in disk cache, so when is restarting it doesn't know about this value and set a max age default which causes that cache is not refreshed until the default max-age value is elapsed. I've implemented a patch that fix the error and I would like to know your thoughts about it and if it could affect to normal working of polipo. I've attached the patch. Thanks in advance. ------------------------------------------------------------------------------ The Go Parallel Website, sponsored by Intel - in partnership with Geeknet, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials, tech docs, whitepapers, evaluation guides, and opinion stories. Check out the most recent posts - join the conversation now. http://goparallel.sourceforge.net/ _______________________________________________ Polipo-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/polipo-users
0001-Polipo-ignores-cache-control-values-when-it-has-rest.patch
(application/octet-stream, 2.8 KB)
From 275d6e2c874bf85b4f68a88ff9dfdc3ef55f8617 Mon Sep 17 00:00:00 2001 From: Ruben Alleres <[email protected]> Date: Fri, 15 Feb 2013 16:50:48 +0000 Subject: [PATCH] Polipo ignores cache control values when it has restarted. The max-age value of Cache-control could be received in a http header. Polipo web cache proxy should be set this value as the maximum time that this page is stored in cache. When max-age has elapsed the cache is stale and it should be refreshed making a new request to the server. Polipo's is saving the cache control values in memory but they are not saved on disk doing that polipo doesn't know the cache control values when is restarted and setting them with a default value. httpPrintCacheControl is the polipo's function which writes the values from a CacheControlRec object in a buffer. It has two callers: - httpWriteRequest which does pass in a CacheControlRec object. - httpWriteObjectHeaders which did pass a NULL object rather a CacheControlRec object. httpWriteObjectHeaders is called when polipo writes the header values on disk cache so some cache control values was never written on disk. It has been updated to write cache-control values on disk. Updated the call to httpPrintCacheControl from httpWriteObjectHeaders passing an updated CacheControlRec object as parameter. Updated validateEntry function to fill the memory cache-control values when they has been read from disk cache. --- diskcache.c | 2 ++ http.c | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletions(-) diff --git a/diskcache.c b/diskcache.c index baaf079..7756209 100644 --- a/diskcache.c +++ b/diskcache.c @@ -1048,6 +1048,8 @@ validateEntry(ObjectPtr object, int fd, dirty = 1; object->cache_control |= cache_control.flags; + object->max_age = cache_control.max_age; + object->s_maxage = cache_control.s_maxage; if(object->age < 0) object->age = object->date; if(object->age < 0) object->age = 0; /* a long time ago */ diff --git a/http.c b/http.c index cc207f8..1d5c9f9 100644 --- a/http.c +++ b/http.c @@ -293,6 +293,13 @@ httpWriteObjectHeaders(char *buf, int offset, int len, ObjectPtr object, int from, int to) { int n = offset; + CacheControlRec cache_control; + + cache_control.flags = object->flags; + cache_control.max_age = object->max_age; + cache_control.s_maxage = object->s_maxage; + cache_control.max_stale = -1; + cache_control.min_fresh = -1; if(from <= 0 && to < 0) { if(object->length >= 0) { @@ -358,7 +365,7 @@ httpWriteObjectHeaders(char *buf, int offset, int len, } n = httpPrintCacheControl(buf, n, len, - object->cache_control, NULL); + object->cache_control, &cache_control); if(n < 0) goto fail; -- 1.7.1