Cannot invalidate template cache (by element) on entries.onDeleteEntry I'm trying to do craft()-&gt;templateCache-&gt;deleteCachesByElementId on entries.onDeleteEntry, unsuccessfully.

The event listener is working, but the caches don't get invalidated.

Here's the code:

public function init()
{
    craft()-&gt;on('entries.onSaveEntry', function($event) {
        $this-&gt;clearEntryCache($event);
    });

    craft()-&gt;on('entries.onDeleteEntry', function($event) {
        $this-&gt;clearEntryCache($event);
    });

}

public function clearEntryCache(Event $event) {
    $entry = $event-&gt;params['entry'];
    craft()-&gt;templateCache-&gt;deleteCachesByElementId($entry-&gt;id, true);
}



entries.onSaveEntry works perfectly.
Instead of run deleteCachesByElementId, if I deleteAllCaches, it works (but I don't want to do this)
I've also tried entries.onBeforeDeleteEntry with no luck.
I've tried deleting from the entry, and from the entry listing (bulk delete) screen.


On the surface it seems maybe it isn't working because by the time deleteCachesByElementId, the element is already deleted...though it still seems there should be a way to delete that cache with the elementId reference.
Ok so here's what did it:
In my plugin, I had to manually call:

        craft()-&gt;templateCache-&gt;includeElementInTemplateCaches($entry-&gt;id);


With that, I didn't need had any of my event listeners in place.

Interesting that things seem to be inserted into craft_templatecachecriteria automatically, but not into craft_templatecacheelements...Perhaps that is bug?