cache matrix impl