backported better caching from FG 1.2