user preferences: MDL-17123 cope correctly with multiple sessions.
This steals the logic from accesslib used to detect dirty contexts and so reload cached access data when permissions are changed.
Here, we track when user preferences are changed, so that if necessary we can trigger a reaload. This helps in two situations:
1. When you are logged into Moodle with two different browsers.
2. When someone else changes one of your preferences.
After this change, you will see the changed user pref immediately in all sessions.
This adds one cheap DB query to any page that tries to access a user preference (which is almost all of them, because of deciding whether to show the messaging pop-up). It adds a few more queries in the cases when a user preference is changed. This is in the name of correctness.