I want to do the following thing: a method getSessionToken
which would:
make a request to a server if a "
cachedSessionToken
" is outdated (made more than 1 hour ago)once it has made the request to the server, it saves a result to a "
variable
" and then returns it whenevergetSessionToken
is called
So the idea is cache a result and return is when needed, otherwise make the request to the server getSessionTokenRemote
first, cache it and only after that return the result. I'm not interested in exact implementation of getSessionTokenRemote
, however, it could be something like this:
getSessionTokenRemote :: IO String
-- or just
getSessionTokenRemote :: String
whatever is the best fit.
I wonder, how do I do that in a pure functional language such Haskell?