Ensure GC doesn't interfere with cache. Closes #3789.

Since the cache uses soft references, it was previously possible for
an object to be in the cache (or put in the cache) and then be gone
by the time the final cache.get was called. Keeping a hard reference
in the method itself prevents this from happening.