moved canvas cache to a global variable