Skip to content

Commit

Permalink
better cache cleanup
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@621 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
borg-0300 committed Aug 31, 2005
1 parent 2e6df95 commit c1d7527
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion source/de/anomic/plasma/plasmaHTCache.java
Expand Up @@ -201,7 +201,34 @@ public void writeFileAnnouncement(File file) {
}
}

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)) {
Expand All @@ -220,7 +247,7 @@ private void cleanup() {
}
}
}
}
}*/

public void close() throws IOException {
responseHeaderDB.close();
Expand Down

0 comments on commit c1d7527

Please sign in to comment.