Use local variables where appropriate.
Do not overwrite the cache if we know nothing new will be writen.