Improve TokenUtils performance through caching

For #9717.

For testing, you can take https://gist.github.com/MarcelGerber/5c11f1031af292044708, placing your cursor in the script tags and pressing `Ctrl-Space`.
I haven't tested it, but the CM manual said it returns the mode at the given pos.
I'll look into the unit tests and the Travis failure soon.