Template caching

Closes #2