cachedmatrix implementation