caching inverse matrix solver