The absorption of broadband photons in atomic ensembles requires either an effective broadening of the atomic transition linewidth, or an off-resonance Raman interaction. Here, we propose a scheme for a quantum memory capable of storing and retrieving ultrafast photons in an ensemble of two-level atoms using a propagation medium with a time–dependent refractive index generated from aligning an ensemble of gas-phase diatomic molecules. The refractive index dynamics generates an effective longitudinal inhomogeneous broadening of the two-level transition. We numerically demonstrate this scheme for storage and retrieval of a weak pulse as short as 50 fs, with a storage time of up to 20 ps. With additional optical control of the molecular alignment dynamics, the storage time can be extended about one nanosecond leading to time–bandwidth products of order 10⁴. This scheme could in principle be achieved using either a hollow-core fibre or a high-pressure gas cell, in a gaseous host medium comprised of diatomic molecules and a two-level atomic vapour at room temperature.