implement cache matrix

implement cache matrix.
Assignment #2