Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Charles 42 posts 63 karma points
    Mar 16, 2014 @ 04:12
    Charles
    0

    Changing Nodes properties only show up 1 time, and not after first change, Please Help

    Well, using Umbraco 4.6.1 here, and when I change the property of a Node, it shows up the first time, but than after changing it again, it doesn't change on the front end again. I can only change it once and it will show. I don't understand what I'm doing wrong here.

    So, I have a .cs file in the AppCode directory structure, and have controls using the function in the .cs files... like so:

    public static Content GetCached (Node aNode) 
    {
        Content theContent = new Content();
    
        try
        {
            string theCacheKey = "Content:" + aNode.Id;
    
            if (System.Web.Hosting.HostingEnvironment.Cache[theCacheKey] == null)
            {
    
                lock (_Lock)
                {
                    if (System.Web.Hosting.HostingEnvironment.Cache[theCacheKey] == null)
                    {
    
                        theContent = Content.Parse(aNode);                            
                        System.Web.Hosting.HostingEnvironment.Cache.Insert(theCacheKey, theContent); 
                        UmbracoHelper.AddCacheKey(theCacheKey);
                    }
                }
            }
    
            theContent = (Content)System.Web.Hosting.HostingEnvironment.Cache[theCacheKey];
    
        }
        catch (Exception ex)
        {
            ErrorHelper.LogError("Content:GetCached", ex);
        }           
        return theContent;
    }
    

    I call upon the Node and it's properties like this:

    MMG.BusinessLayer.Content _Content = new MMG.BusinessLayer.Content();
    

    // Inside the function call is this:

    _Content    = MMG.BusinessLayer.Content.GetCached(Context.GetContent());
    

    And GetContent method looks like this:

    public static Node     GetContent  (this HttpContext aContext) 
    { 
        if (aContext.Items["Content"] == null)
        {
            Node theNode = new Node();
    
            try
            {
                int theContentID = 0;
    
                if (int.TryParse(aContext.Request["cid"], out theContentID))
                {
                    try
                    {
                        theNode = new Node(theContentID);
                    }
                    catch (Exception ex)
                    {
                        ErrorHelper.LogError("ContextExtensions:GetContent", ex);
                    }
                }
                else
                {
                    Location theLocation = aContext.GetLocation();
                    Node     theSiteNode = new Node(theLocation.ParentID);
    
    
                    foreach (Node theFolderNodes in theSiteNode.Children)
                    {
                        if (theFolderNodes.NodeTypeAlias == "Folder")
                        {
                            foreach (Node theChildNode in theFolderNodes.Children)
                            {
                                if (theChildNode.NodeTypeAlias == "Home")
                                {
                                    theNode = theChildNode;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHelper.LogError("ContextExtensions:GetContent", ex);
            }
    
            aContext.Items.Add("Content", theNode);
        }
    
        return (Node)aContext.Items["Content"];
    }
    

    What could be the problem?

  • Charles 42 posts 63 karma points
    Mar 16, 2014 @ 04:47
    Charles
    0

    Ok, so I found out something now. When I remove the lock (_Lock) statement, it updates fine everytime. That must be some sort of way they unlock the ability for the content to be updated.

    But where do I need to look to be able to figure out that part of the code?? Hmmmm, must be a GLOBAL variable of some sort somewhere.... hmmm

    In the declaration of that file, Content.cs, it says this:

    private static object   _Lock = "";
    

    Awwww, I believe it was there to lock any updating of content. Nice!!!

Please Sign in or register to post replies

Write your reply to:

Draft