Add caching to the log in function.