Described is a spring-loaded cartridge cap for use in a drug infusion pump. The cap is ejected if it is not properly inserted into the pump. In one embodiment, the cap includes three detent pins that mate with detents in a cartridge chamber within the drug infusion pump. As the cap is inserted into the cartridge chamber of the drug infusion pump, the distal end of the cartridge compresses a coil spring within the cap. To secure the cap within the cartridge chamber, the cap is rotated such that each detent pin moves within a slot until a locking detent is engaged.