I'm working on a simple project that shows some data that I'd like to see everyday. This will go on to my raspberry-pi. I'm using a free api that has a limit on requests so I thought I'd cache the requests so I don't spam the API. Here is what I've got so far:
(def KEY "Cache-Key")
(def CF (cache/ttl-cache-factory {} :ttl 43200)) ; 12 hour cache
(defn get-data-from-api
[url]
(let [response {:cache true :value 1}]
(println "---> getting from http")
response))
(defn get-data
[url]
(cache/lookup-or-miss CF KEY (get-data-from-api url)))
According to this link, this is all that is required. Except:
- my
get-datafunction always gets it from the api (theprintlnI added to debug gets printed always). The cache is being added just fine, just doesn't seem to fetch and return - The
get-datadoesn't return anything. So when I docurl http://localhost:3001/displayI get an empty response.
Am I using the cache correctly please?