Cachex example with TTL?

I’m trying to cache the result of an HTTP lookup – the HTTP response does include a valid “expires” header. My goal was to cache the response for a TTL that matches that expiration datetime. Cachex offers a simple interface for accessing values from cache and falling back to the HTTP lookup, but I don’t see where to set the TTL values of the cache keys. There’s a page in its docs about TTLs, but it doesn’t show how to actually implement them. Or am I missing something? Thanks!

1 Like

put something with a TTL of 60 seconds.

Cachex.put(:my_cache, "key", "value", ttl: :timer.seconds(60))

Maybe I’m misunderstanding your question.


Thank you! I constantly struggle with locating relevant information in the Hex docs. There’s a dedicated page helpfully titled “TTL” but it doesn’t contain examples or a link to the page you shared.


oh good! I’m glad that helped!