Fix crash due to undefined 'timeout' variable; fix cache timeout calculation

The API was crashing on me on cache accesses due to `timeout` not being defined anywhere; I assumed you meant to use TTL. Also changed the direction of the less-than operator. :)