Maybe 60-90 minutes for liquid. Up to 20-30+ minutes before is usually a chew/tablet/gum version. Studies show you benefit by getting caffeine into the system. If you're fueling for longer races, it's helpful to continue to add in caffeine to keep levels elevated but 8k is still relatively short. That 30-90 minute window should work well but practice it. I don't like liquids 90ish minutes before a race.
Where are you getting an hour and a half for liquid vs. 20 min for a chew??
Personal anecdote. Was trying to get a feel for what OP was asking -- I wouldn't down an energy drink with less than an hour to go before a race. That would be sloshing around my stomach and causing all sorts of problems. I can have caffeine in solid form pretty close to working out. Maybe it isn't the same for everyone but I don't want liquids at least 60 minutes before a race.
What source are you looking to consume (pre-workout powder, can of pre, coffee, gel, pill, etc), how much caffeine do you usually consume/day (100, 300, 500mg, etc), and how much on race day? Ideally you've incorporated this into your training, even if just 1x/2 wks.