My guess is that the code above is inside a template operator or similar which is called inside a template that is cached in view cache or cache-block.
You can disable both using site.ini settings for development, but for prod you should never disable cache unless you have a very low traffic site and you don't care about its performance, and green house gases.. :)