cache and compute inverse of a square matrix