Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2003-01-31 17:58:44 +0000
committerMichael Valenta2003-01-31 17:58:44 +0000
commiteec2fc3383784c788c1278e493ee9008fd9ec61f (patch)
treeea621e7ff282759ff5befb8f349ca89e33633aa8
parent372c49551ad09ee17fe3e069b89c37915ef5a720 (diff)
downloadeclipse.platform.team-eec2fc3383784c788c1278e493ee9008fd9ec61f.tar.gz
eclipse.platform.team-eec2fc3383784c788c1278e493ee9008fd9ec61f.tar.xz
eclipse.platform.team-eec2fc3383784c788c1278e493ee9008fd9ec61f.zip
29844: File cache grows infinitely
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java45
1 files changed, 43 insertions, 2 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java
index 1f7d70530..d081a16fe 100644
--- a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/CVSProviderPlugin.java
@@ -18,6 +18,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Date;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
@@ -87,8 +89,12 @@ public class CVSProviderPlugin extends Plugin {
// Directory to cache file contents
private static final String CACHE_DIRECTORY = ".cache"; //$NON-NLS-1$
+ // Maximum lifespan of local cache file, in milliseconds
+ private static final long CACHE_FILE_LIFESPAN = 60*60*1000; // 1hr
private Hashtable cacheFileNames;
+ private Hashtable cacheFileTimes;
+ private long lastCacheCleanup;
private int cacheDirSize;
private QuietOption quietness;
@@ -523,6 +529,8 @@ public class CVSProviderPlugin extends Plugin {
}
file.mkdir();
cacheFileNames = new Hashtable();
+ cacheFileTimes = new Hashtable();
+ lastCacheCleanup = -1;
cacheDirSize = 0;
} catch (IOException e) {
log(new Status(IStatus.ERROR, ID, 0, Policy.bind("CVSProviderPlugin.errorCreatingCache", e.getMessage()), e)); //$NON-NLS-1$
@@ -536,7 +544,8 @@ public class CVSProviderPlugin extends Plugin {
if (file.exists()) {
deleteFile(file);
}
- cacheFileNames = null;
+ cacheFileNames = cacheFileTimes = null;
+ lastCacheCleanup = -1;
cacheDirSize = 0;
} catch (IOException e) {
log(new Status(IStatus.ERROR, ID, 0, Policy.bind("CVSProviderPlugin.errorDeletingCache", e.getMessage()), e)); //$NON-NLS-1$
@@ -553,16 +562,48 @@ public class CVSProviderPlugin extends Plugin {
file.delete();
}
- public File getCacheFileFor(String path) throws IOException {
+ public synchronized File getCacheFileFor(String path) throws IOException {
String physicalPath;
if (cacheFileNames.containsKey(path)) {
+ /*
+ * cache hit
+ */
physicalPath = (String)cacheFileNames.get(path);
+ registerHit(path);
} else {
+ /*
+ * cache miss
+ */
physicalPath = String.valueOf(cacheDirSize++);
cacheFileNames.put(path, physicalPath);
+ registerHit(path);
+ clearOldCacheEntries();
}
+ return getCacheFileForPhysicalPath(physicalPath);
+ }
+ private File getCacheFileForPhysicalPath(String physicalPath) throws IOException {
return new File(getStateLocation().append(CACHE_DIRECTORY).toFile(), physicalPath);
}
+ private void registerHit(String path) {
+ cacheFileTimes.put(path, Long.toString(new Date().getTime()));
+ }
+ private void clearOldCacheEntries() throws IOException {
+ long current = new Date().getTime();
+ if ((lastCacheCleanup!=-1) && (current - lastCacheCleanup < CACHE_FILE_LIFESPAN)) return;
+ Enumeration e = cacheFileTimes.keys();
+ while (e.hasMoreElements()) {
+ String f = (String)e.nextElement();
+ long lastHit = Long.valueOf((String)cacheFileTimes.get(f)).longValue();
+ if ((current - lastHit) > CACHE_FILE_LIFESPAN) purgeCacheFile(f);
+ }
+
+ }
+ private void purgeCacheFile(String path) throws IOException {
+ File f = getCacheFileForPhysicalPath((String)cacheFileNames.get(path));
+ f.delete();
+ cacheFileTimes.remove(path);
+ cacheFileNames.remove(path);
+ }
/*
* Add the repository location to the cahced locations

Back to the top