Copied to clipboard

Flag this post as spam?

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


  • stephanie 52 posts 133 karma points
    Dec 02, 2014 @ 18:47
    stephanie
    0

    Strange Caching Issue

    A little complicated, but here goes. Please keep in mind that my convoluted logic came about because I didn't realize when I created the site that caching could not be accomplished by page.

    I set up my site with 4 blogs, siblings under the home page. 

    The landing page of each blog includes a list of 10 of the latest posts for that particular blog.

    The template for the landing page renders those 10 posts with a cachedpartial, based on the blog id:

     

    @if(Model.Content.Id == 1242)
                    {                    
                        @Html.CachedPartial("uBlogsy/Landing/uBlogsyLandingListPosts1", Model, 3600, false, false, new ViewDataDictionary(ViewData) { { "ItemsPerPage", 10 } })     
                    }
                    @if(Model.Content.Id == 1259)
                    {                    
                        @Html.CachedPartial("uBlogsy/Landing/uBlogsyLandingListPosts2", Model, 3600, false, false, new ViewDataDictionary(ViewData) { { "ItemsPerPage", 10 } })     
                    }
                    @if(Model.Content.Id == 1200)
                    {                   
                        @Html.CachedPartial("uBlogsy/Landing/uBlogsyLandingListPosts3", Model, 3600, false, false, new ViewDataDictionary(ViewData) { { "ItemsPerPage", 10 } })     
                    }
                    @if(Model.Content.Id == 1258)
                    {                    
                        @Html.CachedPartial("uBlogsy/Landing/uBlogsyLandingListPosts4", Model, 3600, false, false, new ViewDataDictionary(ViewData) { { "ItemsPerPage", 10 } })     
                    }
    

    So I've actually cloned the LandingListPosts partial 4 times so I could hardcode the source of the posts (so I could cache the results)

    Now, withing the cached partial, the posts are retrieved like this:

    var itemsPerPage = (int)ViewData["ItemsPerPage"];    
    var posts = PostService.Instance.GetPosts(Umbraco.TypedContent(1242)).Take(itemsPerPage).ToIPublishedContent(true);
        @RenderForLanding(posts)
    }

    The issue I'm having is that I don't always get the correct listing of posts. Sometimes there'll be a few old ones, not the 10 that I'm supposed to retrieve. Sometimes only one. 

    If I republish and hit that landing page immediately, then I get the correct listing of 10 posts, and it stays that way (clearly because it's cached!)

    I know that I've read that a cachedpartial will show the first rendering regardless of any changes in the underlying model. So I'm thinking that somehow the first rendering sometimes pulls an unexpected listing of nodes. 

    Is it possible that the page is being hit during the publishing process and getting unexpected results because it's in the middle of publishing? Does anyone have any idea what I can do to ALWAYS get the latest 10 posts from a blog and cache the results reliably? I really need to cache because of the site traffic vs server resources. Any help would be appreciated!!

    Thanks!

    Steph

  • Anthony Dang 1404 posts 2558 karma points MVP 3x c-trib
    Jan 11, 2015 @ 20:10
    Anthony Dang
    100

    Cache is my worst best friend.

    I never use cached partial unless it's a footer or navigation. 

    I know that someone was able to write their own cached partial which was would cache based on the model that was passed to it. 

    Do you need to cache them? Examine is used under the hood so it should be relatively performant anyway.

     

     

  • stephanie 52 posts 133 karma points
    Jan 12, 2015 @ 17:26
    stephanie
    0

    Anthony, this was "my bad". I wasn't getting the posts the way I said I was on each partial:

    PostService.Instance.GetPosts(Umbraco.TypedContent(1242)).Take(itemsPerPage).ToIPublishedContent(true);

    I left some of them with the original code:

    PostService.Instance.GetPosts(Model.Content, tag, label, author, searchTerm, commenter, year, month, day, out postCount).Skip((page - 1) * itemsPerPage).Take(itemsPerPage).ToIPublishedContent(true);

    Clearly, tag, label, etc was being provided by hitting an author / tag link in the blog -- I hadn't rewritten those links yet.

    Thanks!!

    Steph

Please Sign in or register to post replies

Write your reply to:

Draft