  We present a quantum-state-diffusion equation to characterize the dynamics of
a generic atomic system coupled to a leaky cavity mode. As quantum resources,
the population, the coherence and even the entanglement of the system would
gradually leak out of the cavity. The effect from the leakage of the
cavity-mode to the uncontrollable degree of freedom, e.g., environment, is
however not always negative to particular targets. A well-established scenario
is that a photon counter attached to the cavity would absorb and then record
the leaking photon. As a medium between the system and the photon counter, a
strong coupling between system and cavity is necessary to enhance the
measurement efficiency. While we find it also reduce the reading efficiency of
the photon counter at the same time as fewer photons leak out of the cavity. We
investigate the competition between these two mechanisms in the framework of
non-Markovian open-quantum-system dynamics, where the photon counter serves as
a general bosonic environment. Our results provide an optimized parameter space
for system entanglement preservation and generation.
