Replace cache locking with build directory locking.

Terrifying, yet liberating.

Closes #6294, but iono if it actually fixes the underlying race condition.