Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

better cache cleanup

borg-0300c1d75279294b
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();