cachematrix with updated matrix caching functions