Ported gitfs cache fixes from #7749 into hgfs. refs #3665.