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

For issue #20 

Also has tests and example in the README