WIP: Cache invalidation by entity.

#6043 
WIP
ok, I understand now what you do. Worth adding a comment why it's needed.