/// <summary> /// Search and compile a template with a given key /// </summary> /// <param name="key">Unique key of the template</param> /// <param name="compileIfNotCached">If true - it will try to get a template with a specified key and compile it</param> /// <returns>An instance of a template</returns> public async Task <ITemplatePage> CompileTemplateAsync(string key) { if (IsCachingEnabled) { var cacheLookupResult = TemplateCache.RetrieveTemplate(key); if (cacheLookupResult.Success) { return(cacheLookupResult.Template.TemplatePageFactory()); } } CompiledTemplateDescriptor templateDescriptor = await TemplateCompiler.CompileAsync(key); Func <ITemplatePage> templateFactory = TemplateFactoryProvider.CreateFactory(templateDescriptor); if (IsCachingEnabled) { TemplateCache.CacheTemplate( key, templateFactory, templateDescriptor.ExpirationToken); } return(templateFactory()); }