edited cache matrix to implement the functionality