Fix some bugs in shared cache:

* It was possible for a balance pass to get into an infinite loop.
* Remove an overlapping flag constant