Remove template lookup cache in build mode. Fixes #1301