implement cache matrix