Any "item" in space (cargo, regens, ammo, etc.) will float there indefinitely as long as it's within scanner range of a player ship, assuming it doesn't get blown up or tractored by NPCs.
Once you travel far enough to have the cargo disappear from your contacts list, it will despawn after a set period of time. If I remember correctly, that period of time is 60 seconds.
Can't say how long your cargo gona stay in space, but in majority situations, its enough time to drop it near base, dock, change char to hauler, undock, and pick it up. However, sometimes you can find space around you to be empty. Anyway, if you thinking about some mining, better to have someone with you to help.
Once you go ~6.5k from an object, it is flagged as deletable. Sometimes stuff is deleted right away, sometimes it takes a few minutes, seems to be dependant on server load.