summaryrefslogtreecommitdiff
path: root/content/hlcache.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2010-04-11 20:21:13 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2010-04-11 20:21:13 +0000
commit71de3618f16f43e5fb4fabff5bba66649a8b9595 (patch)
tree2758ec77a93092f7fd6f0112c8ea3df7d1a224f1 /content/hlcache.c
parent7dcc15cbd481386c85810177a3aa50a517c18b37 (diff)
downloadnetsurf-71de3618f16f43e5fb4fabff5bba66649a8b9595.tar.gz
netsurf-71de3618f16f43e5fb4fabff5bba66649a8b9595.tar.bz2
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
Diffstat (limited to 'content/hlcache.c')
-rw-r--r--content/hlcache.c52
1 files changed, 52 insertions, 0 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