From c1d75279294b3dffd814910d86d00e07f60f87a7 Mon Sep 17 00:00:00 2001 From: borg-0300 Date: Wed, 31 Aug 2005 13:07:08 +0000 Subject: [PATCH] better cache cleanup git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@621 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/plasma/plasmaHTCache.java | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/source/de/anomic/plasma/plasmaHTCache.java b/source/de/anomic/plasma/plasmaHTCache.java index e4f45be63..ff9bef7aa 100644 --- a/source/de/anomic/plasma/plasmaHTCache.java +++ b/source/de/anomic/plasma/plasmaHTCache.java @@ -201,7 +201,34 @@ public final class plasmaHTCache { } } + private void cleanupDoIt(long newCacheSize) { + File f; + long size; + while ((currCacheSize >= newCacheSize) && (cacheAge.size() > 0)) { + f = (File) cacheAge.remove(cacheAge.firstKey()); + if ((f != null) && (f.exists())) { + size = f.length(); + if (f.delete()) { + log.logInfo("DELETED OLD CACHE : " + f.toString()); + currCacheSize -= size; + f = f.getParentFile(); + if (f.isDirectory() && (f.list().length == 0)) { + // the directory has no files in it; delete it also + if (f.delete()) log.logInfo("DELETED EMPTY DIRECTORY : " + f.toString()); + } + } + } + } + } + private void cleanup() { + // clean up cache to have 8% (enough) space for next entries + if ((currCacheSize >= maxCacheSize) && (cacheAge.size() > 0)) { + if (maxCacheSize > 0) cleanupDoIt(maxCacheSize - ((maxCacheSize / 100) * 8)); + } + } + +/* private void cleanupOld() { // clean up cache to have enough space for next entries File f; while ((currCacheSize > maxCacheSize) && (cacheAge.size() > 0)) { @@ -220,7 +247,7 @@ public final class plasmaHTCache { } } } - } + }*/ public void close() throws IOException { responseHeaderDB.close();