I wouldn't say it's optional, though if you omitted it the sentence's meaning would still be clear. "Taking <drug>" suggests a deliberate attempt to take just that drug; e.g. "taking aspirin" means taking tablets or pills.
On the other hand, there are lots of ways of "taking in caffeine" - drinking coffee, drinking tea, drinking Coca Cola, eating some coffee-flavoured chocolates....
- For Teachers