diff options
-rw-r--r-- | content/hlcache.c | 52 | ||||
-rw-r--r-- | content/hlcache.h | 8 | ||||
-rw-r--r-- | 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, @@ -87,6 +88,17 @@ static void hlcache_content_callback(struct content *c, ******************************************************************************/ /* 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, hlcache_handle_callback cb, void *pw, @@ -267,6 +279,46 @@ nserror hlcache_handle_abort(hlcache_handle *handle) ******************************************************************************/ /** + * 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 * * \param handle Handle for which event is issued diff --git a/content/hlcache.h b/content/hlcache.h index 9f03052fa..1c4cc7b2f 100644 --- a/content/hlcache.h +++ b/content/hlcache.h @@ -64,6 +64,14 @@ enum hlcache_retrieve_flag { }; /** + * 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 * * \param url URL of the object to retrieve handle for 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; |