Cache validation result.

Rebased version of #303/#290
Okay, I can probably work on these changes this week sometime.