From: Daniel Carl Date: Mon, 4 Aug 2014 22:19:00 +0000 (+0200) Subject: Added soup caching support. X-Git-Url: https://git.owens.tech/rss.xml/rss.xml/git?a=commitdiff_plain;h=716d6d7c1b86eb7d440bad3f28c8c766eaabc4db;p=vimb.git Added soup caching support. Added new settings maximum-cache-size to set the size all the cache may use. Default is 2000kB. --- diff --git a/doc/vimb.1 b/doc/vimb.1 index 7944334..7a1d53a 100644 --- a/doc/vimb.1 +++ b/doc/vimb.1 @@ -1047,6 +1047,10 @@ link. Default you have to escape the '|' as '\\|' else the '|' will terminate the :set command and start a new command. .TP +.B maximum-cache-size (int) +Size in kB used to cache various page data. This caching is independent from +`pagecache' or `offlinecache'. To disable caching, the size could be set to '0'. +.TP .B previouspattern (list) Patterns to use when guessing the previous page in a document. Each pattern is successively tested against each link in the page beginning from the last diff --git a/src/config.def.h b/src/config.def.h index af20027..dd3c2b1 100644 --- a/src/config.def.h +++ b/src/config.def.h @@ -46,7 +46,8 @@ #endif /* enable HTTP Strict-Transport-Security*/ #define FEATURE_HSTS - +/* enable soup caching - size can be configure by maximum-cache-size setting */ +#define FEATURE_SOUP_CACHE /* time in seconds after that message will be removed from inputbox if the * message where only temporary */ diff --git a/src/main.c b/src/main.c index b8f10d9..10199f6 100644 --- a/src/main.c +++ b/src/main.c @@ -1004,6 +1004,14 @@ static void session_init(void) * when the setting hsts=on */ vb.config.hsts_provider = hsts_provider_new(); #endif +#ifdef FEATURE_SOUP_CACHE + /* setup the soup cache but without setting the cache size - this is done in setting.c */ + char *cache_dir = util_get_cache_dir(); + vb.config.soup_cache = soup_cache_new(cache_dir, SOUP_CACHE_SINGLE_USER); + soup_session_add_feature(vb.session, SOUP_SESSION_FEATURE(vb.config.soup_cache)); + soup_cache_load(vb.config.soup_cache); + g_free(cache_dir); +#endif } static void session_cleanup(void) @@ -1014,6 +1022,12 @@ static void session_cleanup(void) g_object_unref(vb.config.hsts_provider); soup_session_remove_feature_by_type(vb.session, HSTS_TYPE_PROVIDER); #endif +#ifdef FEATURE_SOUP_CACHE + /* commit all cache writes */ + soup_cache_flush(vb.config.soup_cache); + /* make sure that the cache will be kept on next browser start */ + soup_cache_dump(vb.config.soup_cache); +#endif } static void register_init(void) diff --git a/src/main.h b/src/main.h index cc5bc83..dc513e3 100644 --- a/src/main.h +++ b/src/main.h @@ -323,6 +323,9 @@ typedef struct { gboolean kioskmode; #ifdef FEATURE_HSTS HSTSProvider *hsts_provider; /* the hsts session feature that is added to soup session */ +#endif +#ifdef FEATURE_SOUP_CACHE + SoupCache *soup_cache; /* soup caching feature model */ #endif GHashTable *settings; } Config; diff --git a/src/setting.c b/src/setting.c index 41f1c0e..d803b8b 100644 --- a/src/setting.c +++ b/src/setting.c @@ -80,6 +80,9 @@ static int fullscreen(const char *name, int type, void *value, void *data); #ifdef FEATURE_HSTS static int hsts(const char *name, int type, void *value, void *data); #endif +#ifdef FEATURE_SOUP_CACHE +static int soup_cache(const char *name, int type, void *value, void *data); +#endif static gboolean validate_js_regexp_list(const char *pattern); void setting_init() @@ -200,6 +203,10 @@ void setting_init() setting_add("download-use-external", TYPE_BOOLEAN, &off, NULL, 0, NULL); #ifdef FEATURE_HSTS setting_add("hsts", TYPE_BOOLEAN, &on, hsts, 0, NULL); +#endif +#ifdef FEATURE_SOUP_CACHE + i = 2000; + setting_add("maximum-cache-size", TYPE_INTEGER, &i, soup_cache, 0, NULL); #endif setting_add("x-hint-command", TYPE_CHAR, &":o ;", NULL, 0, NULL); @@ -806,6 +813,22 @@ static int hsts(const char *name, int type, void *value, void *data) } #endif +#ifdef FEATURE_SOUP_CACHE +static int soup_cache(const char *name, int type, void *value, void *data) +{ + int kilobytes = *(int*)value; + + soup_cache_set_max_size(vb.config.soup_cache, kilobytes * 1000); + + /* clear the cache if maximum-cache-size is set to zero - note that this + * will also effect other vimb instances */ + if (!kilobytes) { + soup_cache_clear(vb.config.soup_cache); + } + return SETTING_OK; +} +#endif + /** * Validated syntax given list of JavaScript RegExp patterns. * If validation fails, the error is shown to the user. diff --git a/src/util.c b/src/util.c index b75d443..d07909b 100644 --- a/src/util.c +++ b/src/util.c @@ -36,6 +36,10 @@ char *util_get_config_dir(void) return path; } +/** + * Retrieves the path to the cach dir. + * Returned string must be freed. + */ char *util_get_cache_dir(void) { char *path = g_build_filename(g_get_user_cache_dir(), PROJECT, NULL);