Improve cache timeout logic