adding solution for cache matrix