From 71de3618f16f43e5fb4fabff5bba66649a8b9595 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 11 Apr 2010 20:21:13 +0000 Subject: Implement hlcache_poll(), which drives the low-level cache event loop, and attempts to clean the high-level cache. Call this, instead of llcache_poll(). svn path=/trunk/netsurf/; revision=10371 --- content/hlcache.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ content/hlcache.h | 8 ++++++++ desktop/netsurf.c | 4 ++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/content/hlcache.c b/content/hlcache.c index 2a3305387..dd520c8c6 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -73,6 +73,7 @@ static hlcache_entry *hlcache_content_list; /** Ring of retrieval contexts */ static hlcache_retrieval_ctx *hlcache_retrieval_ctx_ring; +static void hlcache_clean(void); static nserror hlcache_llcache_callback(llcache_handle *handle, const llcache_event *event, void *pw); static bool hlcache_type_is_acceptable(llcache_handle *llcache, @@ -86,6 +87,17 @@ static void hlcache_content_callback(struct content *c, * Public API * ******************************************************************************/ +/* See hlcache.h for documentation */ +nserror hlcache_poll(void) +{ + llcache_poll(); + + /* Give the cache a clean */ + hlcache_clean(); + + return NSERROR_OK; +} + /* See hlcache.h for documentation */ nserror hlcache_handle_retrieve(const char *url, uint32_t flags, const char *referer, llcache_post_data *post, @@ -266,6 +278,46 @@ nserror hlcache_handle_abort(hlcache_handle *handle) * High-level cache internals * ******************************************************************************/ +/** + * Attempt to clean the cache + */ +void hlcache_clean(void) +{ + hlcache_entry *entry, *next; + + for (entry = hlcache_content_list; entry != NULL; entry = next) { + next = entry->next; + + if (entry->content == NULL) + continue; + + if (content_count_users(entry->content) != 0) + continue; + + /** \todo This is over-zealous: all unused contents will be + * immediately destroyed. Ideally, we want to purge all + * unused contents that are using stale source data, and + * enough fresh contents such that the cache fits in the + * configured cache size limit. + */ + + /* Remove entry from cache */ + if (entry->prev == NULL) + hlcache_content_list = entry->next; + else + entry->prev->next = entry->next; + + if (entry->next != NULL) + entry->next->prev = entry->prev; + + /* Destroy content */ + content_destroy(entry->content); + + /* Destroy entry */ + free(entry); + } +} + /** * Handler for low-level cache events * diff --git a/content/hlcache.h b/content/hlcache.h index 9f03052fa..1c4cc7b2f 100644 --- a/content/hlcache.h +++ b/content/hlcache.h @@ -63,6 +63,14 @@ enum hlcache_retrieve_flag { HLCACHE_RETRIEVE_MAY_DOWNLOAD = (1 << 31) }; +/** + * Drive the low-level cache poll loop, and attempt to clean the cache. + * No guarantee is made about what, if any, cache cleaning will occur. + * + * \return NSERROR_OK + */ +nserror hlcache_poll(void); + /** * Retrieve a high-level cache handle for an object * diff --git a/desktop/netsurf.c b/desktop/netsurf.c index 248f6fef0..fcd44f642 100644 --- a/desktop/netsurf.c +++ b/desktop/netsurf.c @@ -33,7 +33,7 @@ #include "utils/config.h" #include "utils/utsname.h" #include "content/fetch.h" -#include "content/llcache.h" +#include "content/hlcache.h" #include "content/urldb.h" #include "desktop/netsurf.h" #include "desktop/browser.h" @@ -136,7 +136,7 @@ int netsurf_main_loop(void) { while (!netsurf_quit) { gui_poll(fetch_active); - llcache_poll(); + hlcache_poll(); } return 0; -- cgit v1.2.3