private async Task <ArticleNode> GetArticleNodeAsync(string slug) => await cache.GetOrCreateAsync( $"article|node|{slug}", async entry => { var node = await documentRetriever.GetDocuments <ArticleNode>() .WhereEquals(nameof(TreeNode.NodeAlias), slug) .TopN(1) .FirstOrDefaultAsync(); if (node == null) { entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(20)); return(null); } entry.WithCMSDependency(depends => depends.OnNode(node)); return(node); } );
private async Task <HomeNode> GetHomeNodeAsync( ) => await cache.GetOrCreateAsync( "home|node", async entry => { var node = await documentRetriever.GetDocuments <HomeNode>() .AtRootLevel() .FirstOrDefaultAsync(); if (node == null) { entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(20)); return(null); } entry.WithCMSDependency(depends => depends.OnNode(node)); return(node); } );
public async Task <IEnumerable <Author> > GetAuthorsAsync( ) => await cache.GetOrCreate( "author|all", async entry => { var query = documentRetriever.GetDocuments <AuthorNode>(); if (!query.Any()) { entry.SetAbsoluteExpiration(TimeSpan.FromMinutes(20)); return(Enumerable.Empty <Author>()); } entry.WithCMSDependency(depends => depends.OnNodesOfType <AuthorNode>(SiteNames.BlogTemplate)); return(await query.ToListAsync() .ContinueWith( task => task.Result.Select(mapper.Map <Author>) .ToList() .AsReadOnly() )); } );