Cache validation result.

Rebased version of #303/#290
The additions below aren't yours?