Implemented the cache functionality.