From fe87225ccf284ef4368ec284ce82185871a2194c Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 11 Apr 2010 14:32:39 +0000 Subject: Complete low-level cache cleaner svn path=/trunk/netsurf/; revision=10355 --- content/llcache.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'content/llcache.c') diff --git a/content/llcache.c b/content/llcache.c index 10e466dbf..655b0e728 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -29,6 +29,7 @@ #include "content/fetch.h" #include "content/llcache.h" +#include "desktop/options.h" #include "utils/log.h" #include "utils/messages.h" #include "utils/url.h" @@ -1334,6 +1335,7 @@ nserror llcache_object_snapshot(llcache_object *object, nserror llcache_clean(void) { llcache_object *object, *next; + uint32_t llcache_size = 0; #ifdef LLCACHE_TRACE LOG(("Attempting cache clean")); @@ -1359,6 +1361,8 @@ nserror llcache_clean(void) llcache_object_remove_from_list(object, &llcache_uncached_objects); llcache_object_destroy(object); + } else { + llcache_size += object->source_len + sizeof(*object); } } @@ -1375,11 +1379,37 @@ nserror llcache_clean(void) llcache_object_remove_from_list(object, &llcache_cached_objects); llcache_object_destroy(object); + } else { + llcache_size += object->source_len + sizeof(*object); + } + } + + if ((uint32_t) option_memory_cache_size < llcache_size) { + /* 3) Fresh cacheable objects with + * no users or pending fetches */ + for (object = llcache_cached_objects; object != NULL; + object = next) { + next = object->next; + + if (object->users == NULL && + object->candidate_count == 0 && + object->fetch.fetch == NULL) { +#ifdef LLCACHE_TRACE + LOG(("Found victim %p", object)); +#endif + llcache_size -= + object->source_len + sizeof(*object); + + llcache_object_remove_from_list(object, + &llcache_cached_objects); + llcache_object_destroy(object); + } } } - /* 3) Fresh cacheable objects with no users or pending fetches */ - /** \todo This one only happens if the cache is too large */ +#ifdef LLCACHE_TRACE + LOG(("Size: %u", llcache_size)); +#endif return NSERROR_OK; } -- cgit v1.2.3