/// <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 (cache != null) { var cacheLookupResult = cache.RetrieveTemplate(key); if (cacheLookupResult.Success) { return(cacheLookupResult.Template.TemplatePageFactory()); } } var pageFactoryResult = await templateFactoryProvider.CreateFactoryAsync(key).ConfigureAwait(false); if (cache != null) { cache.CacheTemplate( key, pageFactoryResult.TemplatePageFactory, pageFactoryResult.TemplateDescriptor.ExpirationToken); } return(pageFactoryResult.TemplatePageFactory()); }
private static void CacheTemplate(string templateName, Type templateType, bool isLayout) { var key = new PrecompiledTemplateKey(templateName, isLayout ? ResolveType.Layout : ResolveType.Global); _cachingProvider.CacheTemplate(new PrecompiledTemplate(key, templateType.Assembly, templateType), key); }