Make catfile cache more resistant to double close
It turns out that the fix for Internal error: `file already closed` (#6571 - closed) was a programming error where one use of the catfile cache accidentally duplicated the defer close() line. This mistake ended up poisoning the catfile cache.
It should be possible to detect such a programming error and either explode or at least not poison the catfile cache.