Implement functions to cache and retrieve matrix and its inverse, starting with the templates from #7f657dd