An attempt to clean up ajax code related to cache

nit: This feels large enough to warrant multiple lines

```
var ttl = 0;
if (...) {
  ttl = ...
}
```