untested complete functions
a generic version for caching the results of operations on matrices.