better cache cleanup

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@621 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 20 years ago
parent 2e6df95786
commit c1d7527929

@ -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();

Loading…
Cancel
Save