E. coli is too small to measure a chemical gradient spatially. At 2 micrometers, the concentration difference between its front and back is buried in noise. So it doesn't try. Instead, it measures time.
The bacterium swims in a straight line (a run), then tumbles to pick a new random direction. During each run, it compares current attractant concentration against what it sensed a second or two ago — a chemical memory encoded in methylation state. If things are improving, it suppresses tumbling and keeps running. If not, it tumbles sooner. The result is drift up the gradient, via a biased random walk.
The memory is stored in the same receptor molecules that do the current sensing. Same molecule, both jobs, simultaneously. The record of the past is the current state of the thing that is reading the present.