adapted cachevector to instead cache a matrix in cachematrix