简体   繁体   English

Umbraco通过代码创建内容导致缓存失效

[英]Umbraco Creating Content Through Code Causes Cache Invalidation

We have created an area where the client can manage their content in the site instead of the admin and for some reason when we create new content the cache seems to get invalidated. 我们创建了一个区域,客户端可以在该区域中管理其内容而不是管理员。出于某种原因,当我们创建新内容时,缓存似乎无效。

After creating the content if you go to the node in the admin you will see this error near the Link to Document property: Oops: this document is published but is not in the cache (internal error). 如果转到admin中的节点创建内容后,您将在Link to Document属性附近看到此错误:Oops:此文档已发布但不在缓存中(内部错误)。

Any ideas why this might be happening? 任何想法为什么会这样? Is there a way to check if the item is in the cache after creating it? 有没有办法在创建项目后检查项目是否在缓存中?

This is the method that seems to be causing the issue: 这是导致问题的方法:

public static int GetOrCreateContentFolder(IContentService contentService, int userId, int parentId, string folderName, string contentTypeAlias)
    {
        var targetContentFolder = 
            contentService.GetChildren(parentId)
            .Where(c => c.Name.ToLower() == folderName.ToLower())
            .ToList();

        if (targetContentFolder.Any())
        {
            return targetContentFolder[0].Id;
        }

        var contentFolder = contentService.CreateContent(folderName, parentId, contentTypeAlias, userId);
        return contentFolder.Id;
    }

It seems that you need to publish your new node called "contentFolder". 您似乎需要发布名为“contentFolder”的新节点。

var contentFolder = contentService.CreateContent(folderName, parentId, contentTypeAlias, userId);
contentService.SaveAndPublish(contentFolder);

Use PublishWithChildren if you need to publish all children too. 如果您还需要发布所有孩子,请使用PublishWithChildren

See all methods in the ContentService here: https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService 在此处查看ContentService中的所有方法: https//our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM