Tilmann, one problem with your scheme is that for a lot of queries you do not
know the ids when you do the query (eg, for a thread in forums you know the root message id, but not all the childrens ids).
Another is that with the forums example, adding a post adds an id rather
than changing any existing ids so you have to do an explicit flush on the
parent_id anyway.
A third really hairy issue is that for queries which involve permissions checks,
it would be prohibitive to try to do any real dependency checking; and I
given the varying need for security such queries probably should not
be cached (or at least there should be some option to disable caching of queries involving such checks). Certainly, the experiences with PermissionsCacheP point to a lot of problems with caching such things.
I also think its really easy to go overboard on dependency checking, I have worked with a couple of different systems that had dependency checking for caching or for lazy evaluation and both had numerous places where
checking the dependencies was slower than simply recalculating.
In any case, I definitely approve the tip, although I think it will
be a while before we are really happy with how things work.