Copied to clipboard

Flag this post as spam?

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


  • Jay 425 posts 652 karma points
    Dec 30, 2015 @ 12:24
    Jay
    0

    Hybrid + Donut Caching Preview mode

    Hi All,

    I'm using Umbraco 7.2.4 and was wondering if there's any way to exclude the donut caching bit when we clicked on the "Preview" button?

    The preview doesn't seems to work and it seems to be cached all the time. Is there a way around this and if anyone had came across similar issues?

    Thanks

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 30, 2015 @ 12:30
    Jeroen Breuer
    2

    Hello,

    You could make your own attribute where you exclude the preview. For example:

    public class UmbracoDonutOutputCacheAttribute : DonutOutputCacheAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
    
            var filtered = HttpUtility.ParseQueryString(filterContext.HttpContext.Request.QueryString.ToString());
    
            var previewMode = UmbracoContext.Current.InPreviewMode;
            var debugMode = filterContext.HttpContext.IsDebuggingEnabled;
            var umbDebugMode = filtered["umbDebug"] != null;
    
            if (!previewMode && !umbDebugMode)
            {
                base.OnActionExecuting(filterContext);
            }
            else if (!debugMode && umbDebugMode)
            {
                base.OnActionExecuting(filterContext);
            }
        }
    }
    

    Than you can use it like this: [UmbracoDonutOutputCache]

    Jeroen

  • Jay 425 posts 652 karma points
    Dec 30, 2015 @ 12:41
    Jay
    0

    Ic. Instead of the normal [DonutOutputCache(CacheProfile = "Page")]

    i can use the [UmbracoDonutOutputCache] in my controller?

    Thanks Jeroen. I'll try it out after lunch

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 30, 2015 @ 12:43
    Jeroen Breuer
    0

    Yes that should work.

    [UmbracoDonutOutputCache(CacheProfile = "Page")]
    

    Jeroen

  • Jay 425 posts 652 karma points
    Dec 30, 2015 @ 13:06
    Jay
    0

    Did a quick test. my previewMode var is always true even if i'm not in preview mode. Have you come across that?

    So now when i clicked on the "preview" button, it will reflect on the live version as well. which is weird

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 30, 2015 @ 13:17
    Jeroen Breuer
    0

    Are you sure you're still in preview? Try to logout of the backoffice to make sure.

  • Jay 425 posts 652 karma points
    Dec 30, 2015 @ 14:52
    Jay
    0

    Yup logged out and retried in chrome cognito mode too. Still the same

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Dec 30, 2015 @ 14:55
    Jeroen Breuer
    0

    Hmm that's strange. I never tried the above code. It was an example someone gave to me. Somehow you need to find out if you're in preview mode. When you figure that out update the code and it should work.

    Jeroen

  • Jay 425 posts 652 karma points
    Dec 30, 2015 @ 14:56
    Jay
    0

    I'll try out and update. Thanks Jeroen :)

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Dec 30, 2015 @ 19:47
    Nicholas Westby
    1

    Maybe the cookie itself is also being cached?

    In any event, here is how I avoid caching pages in preview mode: https://github.com/jbreuer/Hybrid-Framework-Best-Practices/issues/2

    Essentially, I change the cache key for any page being previewed.

    There is another solution somebody mentioned there that I haven't tried.

  • Jay 425 posts 652 karma points
    Jan 04, 2016 @ 10:28
    Jay
    0

    Hey Jeroen, the solution that you have actually works. Thumbs up

    It's because of the Preview mode cookie not being killed. Thanks to Nicholas for nothing this down.

    I need to find a way to exit the preview mode (which will kill the preview cookie) as the top right hand exit banner is not showing on mine.

    Kudos to both of you ;)

  • Jay 425 posts 652 karma points
    Jan 04, 2016 @ 10:50
    Jay
    0

    I had a checked on the latest Umbraco 7.3.4 and there's a close button for the preview within the left panel (where you've got all the different devices option).

    I've grabbed the codes amend along with the JS amend for the exit button and it works like a charm

    So you have to edit both files within:
    1. Umbraco\preview\index.html
    2. Umbraco\js\canvasdesigner.panel.js

  • Jay 425 posts 652 karma points
    Jun 19, 2016 @ 00:27
    Jay
    0

    Hi all,

    Have you all encounter similar things before as below.

    I'm using the Umbraco Forms that are rendered into the view as a macro and I'm using my custom attribute like the one above.

    I have my custom controller with the [UmbracoDonutOutputCache(CacheProfile = "Page")] set as usual.

    The form is rendering fine, but the weird thing is, upon clicking on the submit button it shows the below error. When i refresh the page again it will show the "thank you" message. I've checked the form entries and it's saved.

    The form submission work when i comment out the customDonutCache attribute. I've tried to debug and upon form submission it's breaking when it hit the line within UmbracoDonutOutputCacheAttibute.cs of

    base.OnActionExecuting(filterContext);

    Can't figure out how. Appreciate any suggestion / help on this.

    Or is there a way I can exclude the page from cache when there's a form module?

    Thanks

    enter image description here

  • Jay 425 posts 652 karma points
    Jun 19, 2016 @ 09:07
    Jay
    1

    Saw some post in the forum with similar issues and has been told to upgrade the MvcDonutCaching nuget.

    I've upgraded mine to the RC1 version from Nuget which fixes the form post issues. Thought to share if anyone is having similar issues as well

Please Sign in or register to post replies

Write your reply to:

Draft