The diffraction of electromagnetic radiation from periodic grating profiles is determined using rigorous coupled-wave analysis, with intermediate calculations cached to reduce computation time. To implement the calculation, the periodic grating is divided into layers, cross-sections of the ridges of the grating are discretized into rectangular sections, and the permittivity, electric fields and magnetic fields are written as harmonic expansions along the direction of periodicity of the grating. Application of Maxwell's equations to each intermediate layer, i.e., each layer except the atmospheric layer and the substrate layer, provides a matrix wave equation with a wave-vector matrix A coupling the harmonic amplitudes of the electric field to their partial second derivatives in the direction perpendicular to the plane of the grating, where the wave-vector matrix A is a function of intra-layer parameters and incident-radiation parameters. W is the eigenvector matrix obtained from wave-vector matrix A, and Q is a diagonal matrix of square roots of the eigenvalues of the wave-vector matrix A. The requirement of continuity of the fields at boundaries between layers provides a matrix equation in terms of Wand Q for each layer boundary, and the solution of the series of matrix equations provides the diffraction reflectivity. Look-up of W and Q, which are precalculated and cached for a useful range of intra-layer parameters (i.e., permittivity harmonics, periodicity lengths, ridge widths, ridge offsets) and incident-radiation parameters (i.e., wavelengths and angles of incidence), provides a substantial reduction in computation time for calculating the diffraction reflectivity.