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

Change-Id: Ibdf2cbf3c50f6732301d894d91a1b8ea58e4e5d6