Implements cache matrix