The "infinite cavity" has its own problems, as you know when studying QFT in the high-energy-particle context. One way to get well defined observables (S-matrix elements) is indeed to first use a finite "quantization volume". In this context it's wise to use periodic boundary conditions, because this admits the definition of a well-defined momentum operator. So take a cube with length ##L## as the quantization volume. We consider free photons and use the formalism starting from the fully gauge fixed description, i.e., we describe the field by a four-potential ##A^{\mu}## subject to the radiation-gauge condition (only possible for free fields)
$$A^0=0, \quad \vec{\nabla} \cdot \vec{A}=0.$$
The remaining two field components fulfill the wave equation
$$\Box \vec{A}=0.$$
Now we look for plain-wave solutions, leading to
$$\vec{A}_{\vec{k}}=A \vec{\epsilon}_{\vec{k},\lambda} \exp(-\mathrm{i} k \cdot x)|_{k^0=\omega_{\vec{k}}=|\vec{k}|}+\text{c.c.}.$$
##\lambda## labels the two unit vectors (polarization vectors of the wave) perpendicular to ##\vec{k}## since the gauge condition imposes that the waves are transvers:
$$\vec{k} \cdot \vec{\epsilon}_{\vec{k},\lambda}=0.$$
The boundary conditions impose
$$\vec{k} \in \frac{2 \pi}{L} \mathbb{Z}^3,$$
i.e., we have a discrete set of "allowed" momenta. The grid becomes the finer the larger the size of the quantization volume gets, and in the limit of ##L \rightarrow \infty##.
A general field is given by the Fourier series
$$\vec{A}(t,\vec{x})=\sum_{\lambda=1}^2 \sum_{\vec{k} \ in 2 \pi/L \mathbb{Z}^3} [A_{\lambda}(\vec{k}) \epsilon_{\vec{k} \lambda} \exp(-\mathrm{i} k \cdot x)|_{k^0=|\vec{k}|}+\text{c.c.}]$$
The quantization is then straight forward, using the usual Lagrange-Hamilton procedure.
In the infinite-volume limit the sum goes over to an integral over ##\vec{k} \in \mathbb{R}^3##.