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 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'content/hlcache.c') 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; } -- cgit v1.2.3