Add missing db function, correct invalid login in example.
Various updates

Fixed an issue in the role cache where in certain conditions the cache
was not being rebuilt correctly unless a total organization-level
recalculation was performed, which gets expensive with large data sets.