Housekeeping

This commit is contained in:
Peter Taoussanis 2013-10-22 12:58:07 +07:00
parent a29879d1f9
commit de9d1b001e
3 changed files with 6 additions and 5 deletions

View File

@ -174,7 +174,7 @@
(let [timers (atom {})] ; {:hash last-appended-time-msecs ...}
(fn [{ns :ns [x1 & _] :args :as apfn-args}]
(let [now (System/currentTimeMillis)
hash (str ns "/" x1)
hash (str ns "/" x1) ; TODO Alternatives?
limit? (fn [last-msecs]
(and last-msecs (<= (- now last-msecs)
limit-per-msecs)))]

View File

@ -17,6 +17,7 @@
(let [[subject & body] args]
(postal/send-message
(assoc postal-config
;; TODO Better to just use trunc'd message as subject?
:subject (str prefix " - " (or subject throwable))
:body (str (str/join \space body)
(timbre/stacktrace throwable "\n")))))))})

View File

@ -13,13 +13,13 @@
(defn memoize-ttl
"Like `memoize` but invalidates the cache for a set of arguments after TTL
msecs has elapsed."
[ttl f]
[ttl-ms f]
(let [cache (atom {})]
(fn [& args]
(let [{:keys [time-cached d-result]} (@cache args)
now (System/currentTimeMillis)]
(if (and time-cached (< (- now time-cached) ttl))
(if (and time-cached (< (- now time-cached) ttl-ms))
@d-result
(let [d-result (delay (apply f args))]
(swap! cache assoc args {:time-cached now :d-result d-result})