  We present a quantum memory protocol for photons that is based on the direct
control of the transition dipole moment. We focus on the case where the
light-matter interaction is enhanced by a cavity. We show that the optimal
write process (maximizing the storage efficiency) is related to the optimal
read process by a reversal of the {\it effective time} $\tau=\int dt
g^2(t)/\kappa$, where $g(t)$ is the time-dependent coupling and $\kappa$ is the
cavity decay rate. We discuss the implementation of the protocol in a
rare-earth ion doped crystal, where an optical transition can be turned on and
off by switching a magnetic field.
