Clear item from cache programatically

Doing a data import from a file on disk. Trying to delete all children of a node before rebuilding the children. I’m using the following code, but when I check if there’s a node there already, it says yes, even though I consigned them to the Recycle Bin and emptied it! I suspect I need to clear the items from the published cache, but can’t work out how to do it. Any advice appreciated.

var contentItems = courseList.Children()
    .Select(child => contentService.GetById(child.Id)) // Get IContent versions
    .Where(content => content != null) 
    .ToList();

foreach (var contentItem in contentItems) {
    // Unpublish to remove from the frontend (IPublishedContent)
    contentService.Unpublish(contentItem);

    // Move to the Recycle Bin
    contentService.MoveToRecycleBin(contentItem);
}

// Delete the items from the Recycle Bin
foreach (var contentItem in contentItems) {
    contentService.Delete(contentItem);
}

Thanks

Hey Craig,

There was a bug with SaveAndPublish where the IPublishedContent cache didn’t update, I think the work around in that case was to do a Save then a SaveAndPublish.

Just a hunch, and I’m probably wrong, but I wonder if putting a Save in their somewhere might also be the answer in this case perhaps? Worth a try at least.