Code for cache matrix