API 520/521 and ASME code technically wouldn't apply because you are working with piping rather than vessels. However, I've worked at places where similar situations can (and have) occurred. One thing to point out is that you aren't really talking about thermal expansion from a blocked in situtation (ie, solar radiation heating trapped liquid in a loading/offloading line, for example). If you are concerned about the effects of a fire, you've got a bit of a special situation, and there are provisions in the piping codes that require overpressure protection. We've taken several approaches to preventing trapped liquid from overpressurizing line sections. My preference, where feasible, would be to drain the line-automatically blow nitrogen, etc., in order to prevent the line from being liquid full in the first place. This isn't always feasible, so if it's possible to carseal valves open to ensure a relief pathway back to a tank, etc., that's another approach that I've used. Finally, and I must say that this is my least favored approach, is to install either a thermal relief compensator (essentially a bladder tank with a nitrogen pad) or a relief valve, as the last option. Compensators can bleed nitrogen, and if you install a relief valve, well, you've got to make sure you handle the discharge safely, which isn't always the easiet thing to do. I know that other options out there are to drill small (1/4" or less) holes through block valves, once again to provide a relief path-again, not something I favor (you put a block valve there for a reason...) but that's an option that some use.
As Morten mentioned, it's really not a function of line length; rather, it's the potential risk involved with an overpressure in the line (contents, hazard, expansion coefficients, etc.).