Add a limit for graphic cache based on used integer type to avoid overflow

Change-Id: Ibdf2cbf3c50f6732301d894d91a1b8ea58e4e5d6
(cherry picked from commit f20043a0805c3a75eb4024ed59f45291aea93ac0)