Skip to content

Instantly share code, notes, and snippets.

@si14
Last active December 25, 2015 19:59
Show Gist options
  • Save si14/7031212 to your computer and use it in GitHub Desktop.
Save si14/7031212 to your computer and use it in GitHub Desktop.
(defrecord GHCache [^TTLCache ttl-cache etagged cleaner-c])
(defn init-cache []
(let [control-c (chan)
old-killer (fn [etagged]
(let [now (System/currentTimeMillis)]
(->> etagged
(filter #(> (- now (-> % value :created-at))
(* 6 60 60 1000)))
(into {}))))
cache (GHCache. (atom (cache/ttl-cache-factory {} :ttl (* 60 1000)))
(atom {})
(go (let [this (<! control-c)]
(loop []
(<! (timeout (* 6 60 60 1000)))
(swap! (:etagged this) old-killer)
(recur)))))]
(>!! control-c cache)
cache))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment