Matrix Cache function