Version of cachematrix function.