added the logic to set and retrieve cache for matrix inverse