Fix order of merging variables for the combined cache

Fixes #7598