Extract move cache logic to a function

We use the same logic twice - extract it to a function.

Change-Id: I32a257663de37d5f3588c91e4164abceb12ee80d
Merge "Extract move cache logic to a function"