Copied to clipboard

Flag this post as spam?

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


  • Matt Gilbert 24 posts 44 karma points
    Jul 09, 2011 @ 01:22
    Matt Gilbert
    0

    Update a document's cache in the background

    Is there a way to update a document's cache in the background, so that a site visitor always accesses a chaced version, and mever has to wait for a macro to run? I've got a macro that takes a good while to execute, and I would like to be able to update it's cache with something like a scheduled task. But I have had no luck with scheduled tasks so far. Setting up a scheduled task like this:

    <task log="true" alias="MapJSONUpdate" interval="60" url="http://localhost/the-document/MapJSON_UC.aspx"/>
  • Matt Gilbert 24 posts 44 karma points
    Jul 09, 2011 @ 01:28
    Matt Gilbert
    0

    (continued)

    doesn't seem to work. I still need to wait for the page to load after the macro's cache perios (600 seconds) runs out. Is scheduled tasks the way to do something like this, or is there a better way? If Scheduled Tasks is the way to go, how can I determine why the tasks aren't run? (I'm using the Log Manager package, which isn't showing anything.)

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 09, 2011 @ 12:15
    Dirk De Grave
    0

    Hi Matt,

    I'm not sure why you're trying to build a scheduled task to cache a macro's ouput, as it can be done out of the box with umbraco. Just go to developer section, click any macro, and you should be able to set caching period in seconds. Macro output will be cached for x seconds, or until a document is being published in the backend, in which case all cache is invalidated.

     

    Cheers,

    /Dirk

  • Matt Gilbert 24 posts 44 karma points
    Jul 09, 2011 @ 15:30
    Matt Gilbert
    0

    Yes, but after x seconds some visitor will have to wait for the macro to run. I would prefer no one ever have to wait for this macro to run, even though it's only a few seconds. If a background process could update the cache ever x/2 seconds, it would only ever run on the server's time. 

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 09, 2011 @ 16:25
    Dirk De Grave
    0

    Matt,

    Instead of looking for alternative caching solutions, I'd look into why your macro is running so slow. You say it takes a few seconds to run a macro... Honestly, that's really bad, so you may consider looking into a more optimized version of your macro if possible. 

     

    Cheers,

    /Dirk

  • Matt Gilbert 24 posts 44 karma points
    Jul 09, 2011 @ 17:09
    Matt Gilbert
    0

    Believe me, I am looking at optimizing the macro. 

    Is there a way to create a process that executes only when certain documents are changed/saved/published?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 09, 2011 @ 17:32
    Dirk De Grave
    0

    Ah sure there is, you can subscribe on the AfterUpdateDocumentCache on the Content class, and check what type of content has been published. And some info on registering to events can be found on the wiki.

     

    Cheers,

    /Dirk

     

     

     

  • Matt Gilbert 24 posts 44 karma points
    Jul 09, 2011 @ 19:07
    Matt Gilbert
    0

    Now that is exteremely helpful, thank you!

    I'm very new to Umbraco and .NET, so I still need a little more context: Is this still a macro? I've only been coding macros so far, and since this doesn't deal with templates or anything, it seems like it must be some other type of project.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Jul 09, 2011 @ 19:27
    Dirk De Grave
    1

    No, this is no macro, it's custom c# code, and in your case, you need to write a class that inherits from ApplicationBase, write a public parameterless contructor to subscribe to the event I mentioned previously and do whatever you need to do in terms of finding out what type of document the event is firing for, and code your caching improvements strategy.

     

    Cheers,

    /Dirk

  • Matt Gilbert 24 posts 44 karma points
    Jul 09, 2011 @ 20:35
    Matt Gilbert
    0

    Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft