Get and cache document categories

Pedro Costa asked on March 7, 2014 06:21

Hi There,

I need to query for all the categories of a document and cache it, however am having problems with the cache dependency, it doesn't seem to be invalidating my custom document's categories when i update the document, am I using the correct dependency below (

Recent Answers


Pedro Costa answered on March 7, 2014 06:22

oops, something went wrong with the post! code is:

public static InfoDataSet<CategoryInfo> GetCurrentDocumentCategories()
{
    return GetDocumentCategories(CMSContext.CurrentDocument.DocumentID, CMSContext.CurrentDocument.ClassName);
}
public static InfoDataSet<CategoryInfo> GetDocumentCategories(int documentId, string className)
{
    className = className.ToLower();
    InfoDataSet<CategoryInfo> dataSet = null;
    using (var cs = new CachedSection<InfoDataSet<CategoryInfo>>(ref dataSet, 5, true, null, string.Format("Custom.DocumentCategories|{0}|byid|{1}", className, documentId)))
    {
        if (cs.LoadData)
        {
            dataSet = CategoryInfoProvider.GetDocumentCategories(documentId, null, "CategoryOrder", -1, null);
            cs.CacheDependency = CacheHelper.GetCacheDependency(string.Format("{0}|byid|{1}", className, documentId));
            cs.Data = dataSet;
        }
    }
    return dataSet;
}
0 votesVote for this answer Mark as a Correct answer

Roman Koníček answered on March 13, 2014 08:06 (last edited on March 13, 2014 08:06)

Hi,

I have checked your code and right now you are using following dependency "cms.menuitem|byid|38", but could you try to use dependency in this format "nodeid|38" instead?

Best regards, Roman Konicek

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.