diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java index 9a57349f5..543511609 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCache.java @@ -45,8 +45,6 @@ package org.eclipse.jgit.lib; import java.io.File; import java.io.IOException; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -202,8 +200,7 @@ public class RepositoryCache { return false; } FileKey key = new FileKey(gitDir, repo.getFS()); - Reference repoRef = cache.cacheMap.get(key); - return repoRef != null && repoRef.get() == repo; + return cache.cacheMap.get(key) == repo; } /** Unregister all repositories from the cache. */ @@ -219,7 +216,7 @@ public class RepositoryCache { cache.configureEviction(repositoryCacheConfig); } - private final ConcurrentHashMap> cacheMap; + private final ConcurrentHashMap cacheMap; private final Lock[] openLocks; @@ -228,7 +225,7 @@ public class RepositoryCache { private volatile long expireAfter; private RepositoryCache() { - cacheMap = new ConcurrentHashMap>(); + cacheMap = new ConcurrentHashMap(); openLocks = new Lock[4]; for (int i = 0; i < openLocks.length; i++) { openLocks[i] = new Lock(); @@ -261,19 +258,15 @@ public class RepositoryCache { } } - @SuppressWarnings("resource") private Repository openRepository(final Key location, final boolean mustExist) throws IOException { - Reference ref = cacheMap.get(location); - Repository db = ref != null ? ref.get() : null; + Repository db = cacheMap.get(location); if (db == null) { synchronized (lockFor(location)) { - ref = cacheMap.get(location); - db = ref != null ? ref.get() : null; + db = cacheMap.get(location); if (db == null) { db = location.open(mustExist); - ref = new SoftReference(db); - cacheMap.put(location, ref); + cacheMap.put(location, db); } else { db.incrementOpen(); } @@ -285,16 +278,13 @@ public class RepositoryCache { } private void registerRepository(final Key location, final Repository db) { - SoftReference newRef = new SoftReference(db); - Reference oldRef = cacheMap.put(location, newRef); - Repository oldDb = oldRef != null ? oldRef.get() : null; + Repository oldDb = cacheMap.put(location, db); if (oldDb != null) oldDb.close(); } private Repository unregisterRepository(final Key location) { - Reference oldRef = cacheMap.remove(location); - return oldRef != null ? oldRef.get() : null; + return cacheMap.remove(location); } private boolean isExpired(Repository db) { @@ -316,8 +306,7 @@ public class RepositoryCache { } private void clearAllExpired() { - for (Reference ref : cacheMap.values()) { - Repository db = ref.get(); + for (Repository db : cacheMap.values()) { if (isExpired(db)) { RepositoryCache.close(db); } @@ -325,7 +314,7 @@ public class RepositoryCache { } private void clearAll() { - for (Iterator>> i = cacheMap + for (Iterator> i = cacheMap .entrySet().iterator(); i.hasNext();) { unregisterAndCloseRepository(i.next().getKey()); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCacheConfig.java index 428dea3e6..28cdaae44 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RepositoryCacheConfig.java @@ -53,8 +53,8 @@ public class RepositoryCacheConfig { /** * Set cleanupDelayMillis to this value in order to switch off time-based - * cache eviction. The JVM can still expire cache entries when heap memory - * runs low. + * cache eviction. Expired cache entries will only be evicted when + * RepositoryCache.clearExpired or RepositoryCache.clear are called. */ public static final long NO_CLEANUP = 0;