diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2010-04-11 14:32:39 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2010-04-11 14:32:39 +0000 |
commit | fe87225ccf284ef4368ec284ce82185871a2194c (patch) | |
tree | 1f2b4684907b759d817e42606fcce692fea890e0 /content/llcache.c | |
parent | 9666787dfa64c7d990cdf189889bb940be3ba537 (diff) | |
download | netsurf-fe87225ccf284ef4368ec284ce82185871a2194c.tar.gz netsurf-fe87225ccf284ef4368ec284ce82185871a2194c.tar.bz2 |
Complete low-level cache cleaner
svn path=/trunk/netsurf/; revision=10355
Diffstat (limited to 'content/llcache.c')
-rw-r--r-- | content/llcache.c | 34 |
1 files changed, 32 insertions, 2 deletions
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; } |