This confused me when I read the code. Actually token is the token + the scope. Would it not be better to have a cacheKey var which is either the token, or the token plus the scope, rather than overwrting the token var? Then you don't need to re-split it below if the cacheKey is not in the cache