Fix #988: Caching generates invalid group values in some cases