mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -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:
parent
49217cef2b
commit
4bf3e2693b
16
src/cache/cache.c
vendored
16
src/cache/cache.c
vendored
@ -21,6 +21,7 @@
|
||||
#include "util/error.h"
|
||||
#include "util/memory.h"
|
||||
#include "util/string.h"
|
||||
#include "util/time.h"
|
||||
|
||||
/* The list of 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)
|
||||
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
|
||||
* 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -685,6 +686,7 @@ normalize_cache_entry(struct cache_entry *cached, off_t truncate_length)
|
||||
truncate_entry(cached, truncate_length, 1);
|
||||
cached->incomplete = 0;
|
||||
cached->preformatted = 0;
|
||||
cached->seconds = time(NULL);
|
||||
}
|
||||
|
||||
|
||||
|
2
src/cache/cache.h
vendored
2
src/cache/cache.h
vendored
@ -44,6 +44,8 @@ struct cache_entry {
|
||||
|
||||
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 data_size; /* The actual size of all fragments */
|
||||
|
||||
|
@ -502,6 +502,11 @@ static struct option_info config_options_info[] = {
|
||||
"is always cached, even if it is over the memory cache size\n"
|
||||
"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"),
|
||||
"memory", 0,
|
||||
N_("Memory cache options.")),
|
||||
|
@ -570,9 +570,9 @@ http_send_header(struct socket *socket)
|
||||
http_end_request(conn, S_OUT_OF_MEM, 0);
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
|
||||
if (!conn->cached) conn->cached = find_in_cache(uri);
|
||||
#endif
|
||||
|
||||
talking_to_proxy = IS_PROXY_URI(conn->uri) && !conn->socket->ssl;
|
||||
use_connect = connection_is_https_proxy(conn) && !conn->socket->ssl;
|
||||
|
||||
@ -786,11 +786,18 @@ http_send_header(struct socket *socket)
|
||||
}
|
||||
|
||||
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) {
|
||||
add_to_string(&header, "If-Modified-Since: ");
|
||||
add_to_string(&header, conn->cached->last_modified);
|
||||
add_crlf_to_string(&header);
|
||||
if (conn->cached->last_modified) {
|
||||
add_to_string(&header, "If-Modified-Since: ");
|
||||
add_to_string(&header, conn->cached->last_modified);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user