From 48b17a5aea05ce997f72cd6a43d7cf12f419306d Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Tue, 10 Aug 2010 19:58:39 +0000 Subject: Rate-limit cache clean attempts svn path=/trunk/netsurf/; revision=10686 --- content/hlcache.c | 19 ++++++++++++++++--- content/llcache.c | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'content') diff --git a/content/hlcache.c b/content/hlcache.c index 1fd6fe4ad..7dc82a42d 100644 --- a/content/hlcache.c +++ b/content/hlcache.c @@ -29,8 +29,9 @@ #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/url.h" #include "utils/ring.h" +#include "utils/url.h" +#include "utils/utils.h" typedef struct hlcache_entry hlcache_entry; typedef struct hlcache_retrieval_ctx hlcache_retrieval_ctx; @@ -151,10 +152,22 @@ void hlcache_finalise(void) /* See hlcache.h for documentation */ nserror hlcache_poll(void) { + static uint32_t last_clean_time; + uint32_t now; + llcache_poll(); - /* Give the cache a clean */ - hlcache_clean(); + /* Only attempt to clean the cache every 5 seconds */ +#define HLCACHE_CLEAN_INTERVAL_CS (500) + now = wallclock(); + + if (now > last_clean_time + HLCACHE_CLEAN_INTERVAL_CS) { + /* Give the cache a clean */ + hlcache_clean(); + + last_clean_time = now; + } +#undef HLCACHE_CLEAN_INTERVAL_CS return NSERROR_OK; } diff --git a/content/llcache.c b/content/llcache.c index 154f7c4a4..98c3d72e2 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -269,6 +269,8 @@ void llcache_finalise(void) /* See llcache.h for documentation */ nserror llcache_poll(void) { + static uint32_t last_clean_time; + uint32_t now; llcache_object *object; fetch_poll(); @@ -284,8 +286,17 @@ nserror llcache_poll(void) llcache_object_notify_users(object); } - /* Attempt to clean the cache */ - llcache_clean(); + /* Only attempt to clean the cache every 5 seconds */ +#define LLCACHE_CLEAN_INTERVAL_CS (500) + now = wallclock(); + + if (now > last_clean_time + LLCACHE_CLEAN_INTERVAL_CS) { + /* Attempt to clean the cache */ + llcache_clean(); + + last_clean_time = now; + } +#undef LLCACHE_CLEAN_INTERVAL_CS return NSERROR_OK; } -- cgit v1.2.3