private void registerRepository(Key location, Repository db) { db.IncrementOpen(); WeakReference<Repository> newRef = new WeakReference<Repository>(db); WeakReference<Repository> oldRef = cacheMap.put(location, newRef); Repository oldDb = oldRef != null ? oldRef.get() : null; if (oldDb != null) oldDb.Dispose(); }
private Repository openRepository(Key location, bool mustExist) { WeakReference<Repository> @ref = cacheMap.GetValue(location); Repository db = @ref != null ? @ref.get() : null; if (db == null) { lock (lockFor(location)) { @ref = cacheMap.GetValue(location); db = @ref != null ? @ref.get() : null; if (db == null) { db = location.open(mustExist); @ref = new WeakReference<Repository>(db); cacheMap.AddOrReplace(location, @ref); } } } db.IncrementOpen(); return db; }