Code for the cached matrix