Copied to clipboard

Flag this post as spam?

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


  • Eric Gaspard 6 posts 58 karma points
    Nov 13, 2014 @ 14:33
    Eric Gaspard
    0

    How to know when content/media cache has been refreshed

    Hello,

    I want to use the content/media service's events to do additionnal tasks after a node is published or unpublished.

    ContentService.Published += ContentService_Published;
    ContentService.UnPublished += ContentService_UnPublished;

    The events are fired according to action done in the Back-Office, no problems.

    However in the handler of these events, I need to access the node's url or browse the content tree but I discovered some strange behaviors :

    • when creating a content, the new node was not present in the tree
    • when modifying a content's name/url, the node in the tree had the previous name/url
    • when deleting a content, the node was still present in the tree

    As I found out, most of the API I called like UmbracoContext.Current.ContentCache.GetById() or UmbracoHelper.NiceUrl() are dependent on informations that are cached. Cache that, when the event is fired, is being refreshed asynchronously.

    I tried to call UmbracoContext.Current.ContentHasChanged() with no effect since the subsequement implementation seems empty. Therefore I tried to wait in the handler and about 4 seconds later, the cache is effectively refreshed.

    However that's really a hit or miss technique, especially since I believe that the refresh time will grow as my data grow. Therefore how can I synchronize with the cache end update ?

    Thanks and regards,

    Eric.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 13, 2014 @ 14:45
    Dennis Aaen
    0

    Hi Eric,

    I am not a backend developer but maybe this overview of events can help you. I hope that you can use these in Umbraco 7 too.

    http://our.umbraco.org/documentation/reference/Events/Document-Events

    Hope this helps,

    /Dennis

  • Eric Gaspard 6 posts 58 karma points
    Nov 13, 2014 @ 14:47
    Eric Gaspard
    0

    Hello Dennis,

    Interesting I'll give it a shot.

    Thanks.

  • Eric Gaspard 6 posts 58 karma points
    Nov 13, 2014 @ 15:38
    Eric Gaspard
    0

    Well no luck, I tried to hook-up on the Document events but those are not fired at all. Because this class is obsolete I believe (I forgot to precise that I'm using the 7.1.8 version).

    Document.AfterPublish += Document_AfterPublish;
    Document.AfterUnPublish += Document_AfterUnPublish;
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 13, 2014 @ 15:58
    Dennis Aaen
    0

    Hi Eric,

    Okay maybe this documentation can help you further, http://our.umbraco.org/documentation/reference/ the Events says for 6+

    Hope this helps,

    /Dennis

  • Eric Gaspard 6 posts 58 karma points
    Nov 13, 2014 @ 16:59
    Eric Gaspard
    0

    Hello Dennis,

    These are the events I have used to hook-up on the content being published or unpublished. Still there is no event related to the cache refreshing status described in this document.

    However I was able to find my grail :

    CacheRefresherBase<PageCacheRefresher>.CacheUpdated += PageCacheRefresher_CacheUpdated;

    This event fires when the cache related to the content is affected. And I can see that this event sometimes is fired after the Published / UnPublished.

    However with that I think I will be able to synchronize my process.

    PS : it exists other "CacheRefresher" dedicated to each node type like MediaCacheRefresher for the Media and such. Look-up into the Umbraco.Web.Cache namespace.

    Thanks,

    Eric.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Nov 13, 2014 @ 17:02
    Jan Skovgaard
    0

    Hi Eric

    The direct links for ContentService events is here http://our.umbraco.org/documentation/reference/Events-v6/ContentService-Events and the direct links for the MediaService link is here http://our.umbraco.org/documentation/reference/Events-v6/MediaService-Events

    Cheers, Jan

Please Sign in or register to post replies

Write your reply to:

Draft