Implemented much better cache handling.