Clean cache and rebuild if template change.

Inspired by
https://github.com/rdnelson/secondcrack/commit/40201cd3a671200929be9a496
bc7d87f6317b2ac