Cache gitfs environments (0.17 branch)

**THIS PULL REQUEST IS AGAINST 0.17**

This commit improves performance by not repeatedly looking up the
list of available environments whenever they are needed, and instead
writing them to a cache file whenever the fileserver is updated (and
changes are found). envs() will prefer the cache if it is available.

This backports #9787 for the upcoming 0.17.5 release.