Implement cachedMatrix