Implement the matrix caching mechanism