Added a few unit tests for caching.  Refactored part of the caching code appropriately.
- Also patched login code.
Merge pull request #73 from kaysoky/MoreCachingTests

Added a few unit tests for caching.  Refactored part of the caching code...