Make sure cache file gets closed if refreshing item fails

This avoids a ResourceWarning in Python 3 when the cache item needs to be
refreshed, and there is a DNS address lookup error, causing SharedItem() to
raise an exception.