How to automatically/programatically expire macro cache?
I have a section of my site where all the content nodes are basically banner ads. I have an XSLT macro that selects the top 4 and renders them on a couple pages. I want to cache this content as it only changes a few times per month. Problem is, as soon as I change the content, add a new node, unpublish a node, etc. I need the cache to be flushed/expired so the macro now shows the latest content with changes.
So far, publishing the page the macro is on is hit or miss. The only thing that works is setting the cache to zero and then back to the amount of time I desire. Is there a way that I can automatically expire the cache when any content changes within this content node?
I'm not too familiar with how the caching works, but I would think publishing the page with the macro is supposed to expire the cache.
But anyway, since I can't realy help with that - how about checking out the Macro Cache Disabler package, you might be able to see what methods they are using to clear the cache and maybe you can do something similar with an AppBase event or the like.
You could tie into the Publish event (http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/event-examples) and use the following code:
How to automatically/programatically expire macro cache?
I have a section of my site where all the content nodes are basically banner ads. I have an XSLT macro that selects the top 4 and renders them on a couple pages. I want to cache this content as it only changes a few times per month. Problem is, as soon as I change the content, add a new node, unpublish a node, etc. I need the cache to be flushed/expired so the macro now shows the latest content with changes.
So far, publishing the page the macro is on is hit or miss. The only thing that works is setting the cache to zero and then back to the amount of time I desire. Is there a way that I can automatically expire the cache when any content changes within this content node?
Hi Connie,
I'm not too familiar with how the caching works, but I would think publishing the page with the macro is supposed to expire the cache.
But anyway, since I can't realy help with that - how about checking out the Macro Cache Disabler package, you might be able to see what methods they are using to clear the cache and maybe you can do something similar with an AppBase event or the like.
HTH,
Tom
Thanks for the info Tom.
Anyone else have any thoughts?
You could tie into the Publish event (http://our.umbraco.org/wiki/reference/api-cheatsheet/using-applicationbase-to-register-events/event-examples) and use the following code:
umbraco.macro.GetMacro(10).removeFromCache()
is working on a reply...