fireproofsocks

fireproofsocks

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!

Most Liked

fmcgeough

fmcgeough

put something with a TTL of 60 seconds.

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

Maybe I’m misunderstanding your question.

fireproofsocks

fireproofsocks

Thank you! I constantly struggle with locating relevant information in the Hex docs. There’s a dedicated page helpfully titled “TTL” https://hexdocs.pm/cachex/ttl-implementation.html but it doesn’t contain examples or a link to the page you shared.

fmcgeough

fmcgeough

oh good! I’m glad that helped!

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement