Foam-Tac is a type of foam-safe contact cement that is designed specifically for foam. Manufactured by Beacon Adhesives. It stays flexible after its dry, so it can be used to make hinges but it also works really well for general construction. It can be used on balsa and carbon-fiber as well as foam, and has many other uses as well.
The large 2oz tube is best if you use a lot of glue. Foam-Tac is also available in smaller 1-oz and “mini” 5ml squeeze tubes.
Regarding shelf life: Here’s a famous quote: