1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

"If-Modified-Since" second approach.

Added document.cache.interval option. When time elapsed since previous access
to the document is less than interval then the document is taken from
the cache. Otherwise the request with filled "If-Modified-Since" and/or
"If-None-Match" header field is sent. By default interval is set to 10 minutes.
This requires the correct time to be set on your machine.
This commit is contained in:
Witold Filipczyk 2006-10-26 11:53:30 +02:00 committed by Witold Filipczyk
parent 49217cef2b
commit 4bf3e2693b
4 changed files with 29 additions and 13 deletions

16
src/cache/cache.c vendored
View File

@ -21,6 +21,7 @@
#include "util/error.h" #include "util/error.h"
#include "util/memory.h" #include "util/memory.h"
#include "util/string.h" #include "util/string.h"
#include "util/time.h"
/* The list of cache entries */ /* The list of cache entries */
static INIT_LIST_HEAD(cache_entries); static INIT_LIST_HEAD(cache_entries);
@ -181,13 +182,6 @@ get_validated_cache_entry(struct uri *uri, enum cache_mode cache_mode)
if (!cached || cached->incomplete) if (!cached || cached->incomplete)
return NULL; return NULL;
#if 0
if (uri->protocol == PROTOCOL_HTTP || uri->protocol == PROTOCOL_HTTPS
|| uri->protocol == PROTOCOL_FILE /* CGI */) {
if (cached->last_modified && cache_mode == CACHE_MODE_NORMAL)
return NULL;
}
#endif
/* A bit of a gray zone. Delete the entry if the it has the stricktest /* A bit of a gray zone. Delete the entry if the it has the stricktest
* cache mode and we don't want the most aggressive mode or we have to * cache mode and we don't want the most aggressive mode or we have to
@ -200,6 +194,13 @@ get_validated_cache_entry(struct uri *uri, enum cache_mode cache_mode)
return NULL; return NULL;
} }
if (cached->cache_mode <= CACHE_MODE_CHECK_IF_MODIFIED
&& cache_mode <= CACHE_MODE_CHECK_IF_MODIFIED
&& (cached->last_modified || cached->etag)) {
if (cached->seconds + get_opt_int("document.cache.interval") < time(NULL))
return NULL;
}
return cached; return cached;
} }
@ -685,6 +686,7 @@ normalize_cache_entry(struct cache_entry *cached, off_t truncate_length)
truncate_entry(cached, truncate_length, 1); truncate_entry(cached, truncate_length, 1);
cached->incomplete = 0; cached->incomplete = 0;
cached->preformatted = 0; cached->preformatted = 0;
cached->seconds = time(NULL);
} }

2
src/cache/cache.h vendored
View File

@ -44,6 +44,8 @@ struct cache_entry {
unsigned int id; /* Change each time entry is modified. */ unsigned int id; /* Change each time entry is modified. */
time_t seconds; /* Access time. Used by 'If-Modified-Since' */
off_t length; /* The expected and complete size */ off_t length; /* The expected and complete size */
off_t data_size; /* The actual size of all fragments */ off_t data_size; /* The actual size of all fragments */

View File

@ -502,6 +502,11 @@ static struct option_info config_options_info[] = {
"is always cached, even if it is over the memory cache size\n" "is always cached, even if it is over the memory cache size\n"
"threshold. (Then of course no other documents can be cached.)")), "threshold. (Then of course no other documents can be cached.)")),
/* FIXME: Write more. */
INIT_OPT_INT("document.cache", N_("Interval"),
"interval", 0, 0, 86400, 600,
N_("Interval between requests for the same document in seconds.")),
INIT_OPT_TREE("document.cache", N_("Memory cache"), INIT_OPT_TREE("document.cache", N_("Memory cache"),
"memory", 0, "memory", 0,
N_("Memory cache options.")), N_("Memory cache options.")),

View File

@ -570,9 +570,9 @@ http_send_header(struct socket *socket)
http_end_request(conn, S_OUT_OF_MEM, 0); http_end_request(conn, S_OUT_OF_MEM, 0);
return; return;
} }
#if 0
if (!conn->cached) conn->cached = find_in_cache(uri); if (!conn->cached) conn->cached = find_in_cache(uri);
#endif
talking_to_proxy = IS_PROXY_URI(conn->uri) && !conn->socket->ssl; talking_to_proxy = IS_PROXY_URI(conn->uri) && !conn->socket->ssl;
use_connect = connection_is_https_proxy(conn) && !conn->socket->ssl; use_connect = connection_is_https_proxy(conn) && !conn->socket->ssl;
@ -786,12 +786,19 @@ http_send_header(struct socket *socket)
} }
if (conn->cached) { if (conn->cached) {
if (!conn->cached->incomplete && conn->cached->head && conn->cached->last_modified if (!conn->cached->incomplete && conn->cached->head
&& conn->cache_mode <= CACHE_MODE_CHECK_IF_MODIFIED) { && conn->cache_mode <= CACHE_MODE_CHECK_IF_MODIFIED) {
if (conn->cached->last_modified) {
add_to_string(&header, "If-Modified-Since: "); add_to_string(&header, "If-Modified-Since: ");
add_to_string(&header, conn->cached->last_modified); add_to_string(&header, conn->cached->last_modified);
add_crlf_to_string(&header); add_crlf_to_string(&header);
} }
if (conn->cached->etag) {
add_to_string(&header, "If-None-Match: ");
add_to_string(&header, conn->cached->etag);
add_crlf_to_string(&header);
}
}
} }
if (conn->cache_mode >= CACHE_MODE_FORCE_RELOAD) { if (conn->cache_mode >= CACHE_MODE_FORCE_RELOAD) {