Biological cells are often found to sense their chemical environment near the single-molecule detection limit. Surprisingly, this precision is higher than simple estimates of the fundamental physical limit, hinting towards active sensing strategies. In this work, we analyse the effect of cell memory, e.g. from slow biochemical processes, on the precision of sensing by cell-surface receptors. We derive analytical formulas, which show that memory significantly improves sensing in weakly fluctuating environments. However, surprisingly when memory is adjusted dynamically, the precision is always improved, even in strongly fluctuating environments. In support of this prediction we quantify the directional biases in chemotactic Dictyostelium discoideum cells in a flow chamber with alternating chemical gradients. The strong similarities between cell sensing and control engineering suggest universal problem-solving strategies of living matter.