matrix reverse cache functions implemented according to assignment