/** * Returns a repository for the given key or null if repository is not found in cache. If * repository is found its openCounter is incremented. When the caller is done with repository it * must call {@link #release} method. * * @param key repository key * @return see above */ @Nullable synchronized Repository get(@NotNull RepositoryCache.FileKey key) { CachedRepository cachedRepository = myRepositories.get(key); if (cachedRepository != null) { Repository result = cachedRepository.getRepository(); cachedRepository.inc(); return result; } return null; }
/** * Adds a new repository with the specified key in cache. Returns the added repository if there * was no repository in cache associated with the given key, otherwise existing repository * associated with the key is returned and its openCounter is incremented. When the caller is done * with repository it must call the {@link #release} method. * * @param key repository key * @param db repository * @return see above */ @NotNull synchronized Repository add(@NotNull RepositoryCache.FileKey key, @NotNull Repository db) { CachedRepository existing = myRepositories.get(key); if (existing == null) { myRepositories.put(key, new CachedRepository(db)); return db; } else { Repository result = existing.getRepository(); existing.inc(); return result; } }