Countercache behavior that can work with trees

Have anyone built a countercachebehavior that can work with trees? If so can you share it?

The problem seems that when you use countercache articles → categories. When save or delete the article it will update counter in categories table. But then the countercache in categories (on parentcategories) does not get fired…

If I am right, I think the event not get fired for updates only on new records and deletes? But does that not invalidate also things like ratings, where one would change his rating and then the countercache would not update itself?

The problem is that it uses updateAll in countercachebehavior which doesnt trigger beforesave and aftersave events, so you can not recursively use countercaches…

// original line below in countercachebehavior
$assoc->getTarget()->updateAll([$field => $count], $updateConditions);
//change here
$records = $assoc->getTarget()->find()->where($updateConditions);

                foreach($records as $record){
                    $record[$field] = $count;
                    $assoc->getTarget()->save($record);
                }