Implement genCacheTtl(res, origTtl). Allow override of TTL based on res.

For issue #20
Merge remote-tracking branch 'origin/pr/22'
don't bother setting keys if ttl is 0