Spam should hold up for several hours, IMHO. Until the seal is broken, it should be close to sterile, then you would need to try to contaminate it as little as possible. As already mentioned, it is loaded with sodium and precooked.

That said, you are looking at some new backpacking foods. Consider ordering a #10 can of Mountain House Rice with Chicken, which right now is selling at under $16 dollars. Stir and divvy the mix into 10 small bags. I use repurposed (clean) mylar snack bags, such as from potato chips. This particular meal has no veggies and too little protein, again, IMHO, but it makes a great base. Most of the MH meals that I have tried do rehydrate easily and well, and have plenty of sauce for flavor. Plan to add in more protein and assorted vegetables. I can easily think up combinations that could provide at least 10 (actually more, but I think there are 10 "servings" in the can.) Cook and dehydrate at least 2.5 pounds of ground chicken or ground turkey to add to your 10 little bags and buy or dehydrate your veggies of choice. I have a very nice dehydrator but have also had good luck with buying dried vegetables through Amazon's Subscribe and Save, and more recently from a small company called Valley Foods, who may still be featuring sales. Add some beans, maybe corn, peppers, and chicken or turkey plus some chili powder and cumin for "Santa Fe Rice and Chicken," Broccoli, and chicken, maybe with Parmesan for Chicken Divan, spinach, Parmesan, and chicken for Chicken and Rice Florentine, etc. You can easily come up with a lot of variations that are fast trail treats.