Umbraco ContentService不更新文档缓存中的checboxlist

时间:2014-02-10 15:47:05

标签: database caching content-management-system umbraco

我正在使用我编码的导入脚本在新的Umbraco v6.1.6网站上创建大约500页。我正在使用ContentService api来创建新页面。它们被创造并且似乎保存得很好。但是,如果我从其中一个新页面请求checbox列表的值,我会得到一个空字符串。

我已经验证了umbraco.config文件中的属性为空但是如果我从Umbraco后台手动保存页面。缓存将使用正确的值更新,我突然得到正确的值。

有没有办法强制缓存更新或其他形式的修复此问题?

这是我正在使用的CreateContent方法:

public static IContent CreateContent(string name, string documentTypeAlias, int parentId, Dictionary properties, bool publish = false, int author = 0)
{
    IContent document = null;

    ContentService contentService = new ContentService();
    document = contentService.CreateContent(
                    name, // the name of the document
                    parentId, // the parent id should be the id of the group node 
                    documentTypeAlias, // the alias of the Document Type
                    author);

    foreach (string property in properties.Keys)
    {
        document.SetValue(property, properties[property]);
    }

    // If publish is true, then save and publish the document
    if (publish)
    {
        contentService.SaveAndPublish(document);
    }
    // Else, just save it
    else
    {
        contentService.Save(document);
    }

    return document;
}

编辑:

查看数据库后,我可以看到cmsContentXml具有该属性,但其中的数据与umbraco.config相同。我查看了cmsPropertyData并且数据存在。所以我想问题是如何从cmsPropertyData获取数据到cmsContentXml?

我的问题是这个问题:https://stackoverflow.com/questions/17722347/umbraco-6-1-1-when-i-publish-content-via-the-content-service-tags-type-property但它没有回复。

1 个答案:

答案 0 :(得分:2)

来自cmsContentXml的数据会被直接转储到umbraco.config文件中,所以谢天谢地,这些数据是一样的。

为了让你的代码更加干净(你总是将文档保存在if和else中,试试这个并将SaveAndPublish方法更新为Publish(在v7中你可以使用PublishWithResult获取发布操作的详细结果:

contentService.Save(document);

// If publish is true, then save and publish the document
if (publish)
{
    contentService.Publish(document);
}

在v7中,您可以查看publishResult。如果出现问题,那么这将告诉你它是什么。最有可能它只是这样工作正常(这可能意味着SaveAndPublish被破坏,但让我们弄清楚publishResult是否有错误。)