Implemented caching matrix.