How can I prevent texture stretching while scaling a mesh?

Since for some reason I’m not able to edit my message:
I tried the technique in the video @Prithvi_Singh posted, and now texture tiling is working perfectly!

Pay attention to transform node, it should convert world to local space.