/** * Indicate to the cache that the client is done using the cached value for the given key. Clients * of {@link ReferenceCountedCache} must call this after finishing using the value retrieved from * the cache. The retrieved is no longer guaraunteed to be valid after it is released back to the * {@link ReferenceCountedCache} * * @param key to cache entry no longer being used by the client. * @throws java.io.IOException if closing the cached value throws an {@code IOException}. */ public void release(final K key) throws IOException { Preconditions.checkState(mIsOpen, "ReferenceCountedCache is closed."); Preconditions.checkNotNull(key); CacheEntry<V> entry = mMap.get(key); Preconditions.checkState(entry != null, "No cached value for key '%s'.", key); synchronized (entry) { if (entry.decrementAndGetCount() == 0) { // We need to remove the entry from the cache and clean up the value. mMap.remove(key); final V value = entry.getValue(); if (mTracking) { ResourceTracker.get().unregisterResource(value); } value.close(); } } }