Cache function for inverse matrices