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:
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.)
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.
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.
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.
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.
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.
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.
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:
(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.)
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
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.
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
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?
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
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.
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
Thank you!
is working on a reply...