Implemented cache logic