Fix mat caching

If bcs were in the mix, the mat_cache was not doing the right thing.