code to speedup inverse matrix calculation using caching in the enviorment