Make branch_setting a function that is passed down and called per request.
As an optimization, its value is cached in a thread-local variable.