Make the Gems cache directory configurable.

See #3011 and the commits for more info. This should be good to go but before this gets merged I'd like a second pair of eyes from @brixen and @dbussink. I also want to wait on Travis to see if I broke anything severe ("works on my box").