Implement matrix cache function