Added a few unit tests for caching.  Refactored part of the caching code appropriately.
- Also patched login code.