ensure calling release_ref() on the cached object only when the lock is not retained