You can store your templates in some file cache or database in source form. On each requiest you should check if cache have been updated (just check timestamp of relevant files). If it have been updated you need to recompile template from cache. If it haven't been updated you can use already compiled templates. This is how
handles its components (as example).