Use local cache more often

Use local cache when there are unbound type variables and where clauses are in scope.

Fixes #18209.

r? @nick29581 
Or rather, use `u8` for this.