From 984285bdd66be4dc4dbccc06fd522eb6b351cff6 Mon Sep 17 00:00:00 2001 From: orbiter Date: Mon, 27 Nov 2006 15:53:42 +0000 Subject: [PATCH] better organisation of dns hit/miss cache flush git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3016 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/http/httpc.java | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/source/de/anomic/http/httpc.java b/source/de/anomic/http/httpc.java index cc2da9278..daf29c0b4 100644 --- a/source/de/anomic/http/httpc.java +++ b/source/de/anomic/http/httpc.java @@ -131,7 +131,8 @@ public final class httpc { private static final kelondroMScoreCluster nameCacheHitAges = new kelondroMScoreCluster(); private static final kelondroMScoreCluster nameCacheMissAges = new kelondroMScoreCluster(); private static final long startTime = System.currentTimeMillis(); - private static final int maxNameCacheAge = 24 * 60 * 60; // 24 hours in minutes + private static final int maxNameCacheHitAge = 24 * 60 * 60; // 24 hours in minutes + private static final int maxNameCacheMissAge = 24 * 60 * 60; // 24 hours in minutes private static final int maxNameCacheHitSize = 3000; private static final int maxNameCacheMissSize = 3000; public static final List nameCacheNoCachingPatterns = Collections.synchronizedList(new LinkedList()); @@ -455,7 +456,7 @@ public final class httpc { if (doCaching) { // remove old entries - flushNameCacheHit(); + flushHitNameCache(); // add new entries synchronized (nameCacheHit) { @@ -465,6 +466,10 @@ public final class httpc { } return ip; } catch (UnknownHostException e) { + // remove old entries + flushMissNameCache(); + + // add new entries nameCacheMiss.add(host); nameCacheMissAges.setScore(host, intTime(System.currentTimeMillis())); } @@ -526,10 +531,10 @@ public final class httpc { } /** - * Removes old entries from the dns cache + * Removes old entries from the dns hit cache */ - public static void flushNameCacheHit() { - int cutofftime = intTime(System.currentTimeMillis()) - maxNameCacheAge; + public static void flushHitNameCache() { + int cutofftime = intTime(System.currentTimeMillis()) - maxNameCacheHitAge; int size; String k; synchronized (nameCacheHit) { @@ -542,6 +547,16 @@ public final class httpc { size--; // size = nameCacheAges.size(); } } + + } + + /** + * Removes old entries from the dns miss cache + */ + public static void flushMissNameCache() { + int cutofftime = intTime(System.currentTimeMillis()) - maxNameCacheMissAge; + int size; + String k; synchronized (nameCacheMiss) { size = nameCacheMissAges.size(); while ((size > 0) &&