Copied to clipboard

Flag this post as spam?

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


  • David Houghton 33 posts 108 karma points
    Oct 16, 2017 @ 10:19
    David Houghton
    0

    Cached Partials - Umbraco 7.6.0

    Update: it looks like my issue relates to cached partials, below is an overview of my problem, but my assumption was incorrect.

    I think ive found a bug in umbraco 7.6.0 relating to the way content is cached, hopefully someone can shed some light on this.

    I have a team member page which lists any events that this team member is responsible for. I have a lookup for these nodes defined in a seperate file in app_code under an EventUtillities namespace:

    public static List<IPublishedContent> getTeamMemberCurrentEvents(int teamMemberId)
            {
                IPublishedContent teamMemberNode = umbracoHelper.TypedContent(teamMemberId);
    
                if(teamMemberNode != null)
                {
                    var currentDate = DateTime.Now.Date;
                    const string eventTeamMemberAlias = "contactDetails";
                    const string eventDateAlias = "eventDate";
                    return homepage.Descendants("event").Where(e =>
                           e != null &&
                           e.HasProperty(eventTeamMemberAlias) && e.HasValue(eventTeamMemberAlias) &&
                           e.GetPropertyValue<IEnumerable<IPublishedContent>>(eventTeamMemberAlias).Any(x => x.Id == teamMemberId) &&
                           e.HasProperty(eventDateAlias) && e.HasValue(eventDateAlias) &&
                           DateTime.Compare(e.GetPropertyValue<DateTime>(eventDateAlias), currentDate) > 0).ToList();
                }
                else
                {
                    return null;
                }
            }
    

    Then on the view:

    @using xxxx.web.Utillities.Events;
    

    And then called by using:

    var teamMemberCurrentEvents = EventsUtillties.getTeamMemberCurrentEvents(teamMemberId);
    

    It does seem to work, but the minute an event passes the threshold for a current event into a previous event the view isnt updated and still shows the event as a current event.

    The method for a previous event is very similar, but a slight change within the date comparision.

    Could someone please shed some light on why this could be please, if i restart my machine it does seem to be updated correctly but this isnt a practical fix.

  • David Houghton 33 posts 108 karma points
    Oct 16, 2017 @ 10:24
    David Houghton
    0

    Update: it seems IIS could be the culprit here, as when stopping and restarting the view is correctly updated... Anyone give a basic IIS user any tips on how to set this up correctly?

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Oct 16, 2017 @ 10:37
    Steve Morgan
    1

    Hi,

    How is the code above called - have you got a cached partial? That would definitely explain the behaviour.

    Steve

  • David Houghton 33 posts 108 karma points
    Oct 16, 2017 @ 10:41
    David Houghton
    0

    Hi Steve, thanks for the reply!

    Yea, the whole block is being called as a partial, trying to keep those views as clean as possible.

    What can I do to get around this?

    Although looking here - https://our.umbraco.org/documentation/reference/templating/mvc/partial-views

    This documentation mentions that if debugging is turned on (which in my instance it is) then caching should be turned off.

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Oct 16, 2017 @ 11:15
    Steve Morgan
    1

    Hi,

    Yes - it should be.

    Just to check are you calling it like:

    @Html.CachedPartial("MyPartialName", new MyModel(), 3600)

    Or @Html.Partial("MyPartialName")

    And it's just a standard page load - e..g you're not fetching the page from AJAX / Angular etc etc?

    Might be worth trying something like:

    @Html.CachedPartial("MyPartialName", new MyModel(), 10) to see?

  • David Houghton 33 posts 108 karma points
    Oct 16, 2017 @ 13:12
    David Houghton
    0

    Just tried that as described, passing in current page Model:

    @Html.CachedPartial("teammember/_my-events", Model, 10)
    

    Still no joy, the partial is being heavily cached.... anything else I can try here please?

    Update: Brought all logic over from partial into main page view, and still the caching problem continues...

    Update 2: I wondered if umbraco.config was being updated with the publish and unpublish of the node, and it indeed does. Strange that the .config and the views are seemingly seeing different things

  • David Houghton 33 posts 108 karma points
    Oct 16, 2017 @ 14:25
    David Houghton
    0

    Finally sorted it.

    Ive extrapolated a lot of my logic into App_Code to clean up my views, plus it gives me a lot of reuseable methods I can call where needed.

    Win win right? Well ive made a right schoolboy error and its been a right monster to track down!

    My utillities file in App_Code is namespaced like so.

    namespace xxx.web.Utillities
    {
        namespace Events
        {
            public class EventsUtillties {
    
                /*1*/
    
                public static List<IPublishedContent> teamMemberEvents(int teamMemberId)
                {
                    /*2*/    
                    /code to get all team member events
                }
    
                public static List<IPublishedContent> getTeamMemberCurrentEvents(int teamMemberId)
                {
                    /*3*/
                    /code to get all team members current events
                }
    
                public static List<IPublishedContent> getTeamMemberPreviousEvents(int teamMemberId)
                {
                    /*4*/
                    /code to get all team members previous events
                }
            }
        }
    }
    

    This allows me to use it like so:

    in the view:

    @using xxxx.web.Utillities.Events;
    var teamMemberId = Model.Content.Id;
    var teamMemberCurrentEvents = EventsUtillties.getTeamMemberCurrentEvents(teamMemberId);
    

    However i noticed i was writing this over and over at places 2, 3, and 4

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    var homepage = umbracoHelper.TypedContentAtRoot().FirstOrDefault(x => x.DocumentTypeAlias == "homepage");
    

    So I tried putting it at point 1. which seemed to work (keyword: seemed), didnt think anything of it and carried on as normal but it looks like (and its so obvious now) that the UmbracoHelper taking in the current state of umbraco context and due to the scoping was being accessible to the methods, well that was casing me problems. Which again made sense that when IIS was reset this was refreshed and I was getting the result I expected, only for everything to immediately break again, leaving me with no other option but to wrongfully blame IIS and partial views.

    Phew, what a day!

Please Sign in or register to post replies

Write your reply to:

Draft