Group A has members 1, 2, 3

	Cached members  1 is a member of A via ""
			2 is a member of A via ""
			3 is a member of A via ""


Group B has members A, 4, 5

	Cached members: 4 is a member of B via ""  $1
			5 is a member of B via ""  $2
			A is a member of B via ""  $3
				1 is a member of B via "$3" $4
				2 is a member of B via "$3" $5
				3 is a member of B via "$3" $6

Group C has members A, B, 6
			6 is a member of C via "" $7
			A is a member of C via "" $8
				1 is a member of C via $8 $9
				2 is a member of C via $8 $10
				3 is a member of C via $8 $11
			B is a member of C via "" $12
				4 is a member of C via $12 $13
				5 is a member of C via $12 $14
				A is a member of C via $12 $15
					1 is a member of C via $15 $16
					2 is a member of C via $15 $17
					3 is a member of C via $15 $18



Group D has members A, C

			A is a member of D via "" $19
				1 is a member of D via $19 $20
				2 is a member of D via $19 $21
				3 is a member of D via $19 $22
			C is a member of D via "" $23
				6 is a member of D via $23 $24
				A is a member of D via $23 $25
					1 is a member of D via $25 $26
					2 is a member of D via $25 $27
					3 is a member of D via $25 $28
				B is a member of D via $23 $29
					4 is a member of D via $29 $30
					5 is a member of D via $29 $31
					A is a member of D via $29 $32
						1 is a member of D via $32 $33
						2 is a member of D via $32 $34
						3 is a member of D via $32 $35

			

Adding a new user, 7,  to group A.


	Add the user to group A in the groups table.

	Find all entries for group A in the cache table.

	For each entry in that list:
		Add "7 is a member of $entry->top  via $entry->id"

Deleting a user, 7, from group A:

	Remove the user from group A in the groups table.
	find all entries in the cache table where the principal id is user 7 and
	the parent id is A. (requires a self join)
		nuke them

	Alternatively:
	 find all entries for A in the cache table.
		For each one, find the child whose id is 7. 
			Nuke it


Adding a group, B to group D.

	Add group B as a member of D in the groups table.
	In the cache table:
		$id = Add group B as a member of D via ""
                
                For each member of group B (4, 5, A):

                       $sid= 4 is a member of D via $id
                       $sid=  5 is a member of D via $id
                       $sid=  A is a member of D via $id

                        if the member is a group itself, recurse down:
                                
                                1 is a member of D via $sid
                                2 is a member of D via $sid
                                3 is a member of D via $sid
                               
                Find all places where D is a member of $foo.
                        Repeat the above procedure, substituting $foo for D
                        and making $id D's id.

Removing B as a member of D:

        Remove B as a member of D in the groups table.
        Find all references to D in the pseudogroups table.
                Find all children of D which are B:
                        Recurse down with the following algorithm:
                        If it's a user, delete it.
                        If it's a group,  recurse through each member, 
                                deleting its children and then deleting the
                                group itself.
