[1.7.x] Fixed #22495 -- Locmem cache.add() failed with infinite timeouts

cache.add() incorrectly succeeded when there was an existing key
with an infinite (None) timeout.
Backport of af5f688392 from master.