Copied to clipboard

Flag this post as spam?

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


  • Edward Dudley 80 posts 121 karma points
    Aug 17, 2009 @ 11:21
    Edward Dudley
    0

    GetXmlDocumentByUrl and caching

    Hi,

    I'm using the GetXmlDocumentByURL extension and passing in a cache time.

    I'm finding that sometimes the XML document returned isn't correct (maybe a server error or some other error) but this is being cached so that all subsequent requests get this garbled XML document.

    What I'd like is to be able to clear the cached XML from the XSLT.  Is this possible?

    I'm also looking into IIS output caching - maybe this would be a better way to handle this?

    Thanks!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 17, 2009 @ 12:13
    Dirk De Grave
    0

    it's possible if you write a small xslt extension or some inline script to clear the cache

    All you need to do is call:

    umbraco.cms.businesslogic.cache.Cache.ClearCacheItem('key');

    (either from xslt extension or through some inline script code -> I'd take the second approach as this is only a single line of code)

     

    Cheers,

    /Dirk

  • Edward Dudley 80 posts 121 karma points
    Aug 17, 2009 @ 14:45
    Edward Dudley
    0

    That sounds perfect - thank you.

    How do I know what the key is though?

  • Edward Dudley 80 posts 121 karma points
    Aug 19, 2009 @ 09:34
    Edward Dudley
    0

    Anyone know anything about how to get the key?

     

    In case anyone else is interested, I've also investigated IIS output caching but it doesn't seem to work with Umbraco.  You can't use the @OutputCache declaration - I think its something to do with the way umbraco renders templates (I've read how it does not work properly with master pages).

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 19, 2009 @ 09:50
    Dirk De Grave
    101

    Edward,

     

    Found some references in the core code :p

    object urlCache = HttpContext.Current.Cache.Get("GetXmlDoc_" + Url);

    and

    HttpContext.Current.Cache.Insert("GetXmlDoc_" + Url, result, null, DateTime.Now.Add(new TimeSpan(0,0, CacheInSeconds)), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Low, null);
    

    Hope this helps.

     

    Regards,

    /Dirk

  • Edward Dudley 80 posts 121 karma points
    Aug 20, 2009 @ 08:39
    Edward Dudley
    0

    Thats great - thanks Dirk!

  • Edward Dudley 80 posts 121 karma points
    Oct 15, 2009 @ 07:33
    Edward Dudley
    1

    For anyone interested, I've written an XSLT extension that can clear any cached macro or page cached by getxmldoc.  I'll make a package some time but heres the code:

    using System;
    using System.Collections.Generic;
    using System.Web;

    namespace cacheClearer
    {
        public class cacheClearer
        {
           
            public static void clearGetXmlDocByURLCache(string url)
            {
                string Key = "GetXmlDoc_" + url;
                if (System.Web.HttpRuntime.Cache[Key] != null)
                {
                    System.Web.HttpRuntime.Cache.Remove(Key);
                }
            }

            public static void clearMacroCache(string macroNodeId)
            {
                string Key = "umbMacro" + macroNodeId;
                if (System.Web.HttpRuntime.Cache[Key] != null)
                {
                    System.Web.HttpRuntime.Cache.Remove(Key);
                }
            }

        }
    }

     

Please Sign in or register to post replies

Write your reply to:

Draft