fix: should remove old template and cache on error.