Auto-expire png files after 7 days
parent
f184616432
commit
368d0787cf
@ -0,0 +1,6 @@
|
||||
(ns asciinema.boundary.expiring-set
|
||||
(:refer-clojure :exclude [conj! contains?]))
|
||||
|
||||
(defprotocol ExpiringSet
|
||||
(conj! [this value expires-at])
|
||||
(contains? [this value]))
|
@ -0,0 +1,14 @@
|
||||
(ns asciinema.component.mem-expiring-set
|
||||
(:require [asciinema.boundary.expiring-set :as exp-set]))
|
||||
|
||||
(defrecord MemExpiringSet [store]
|
||||
exp-set/ExpiringSet
|
||||
|
||||
(conj! [this value _expires-at]
|
||||
(swap! store conj value))
|
||||
|
||||
(contains? [this value]
|
||||
(contains? @store value)))
|
||||
|
||||
(defn mem-expiring-set [{:keys [store]}]
|
||||
(->MemExpiringSet (or store (atom #{}))))
|
@ -0,0 +1,28 @@
|
||||
(ns asciinema.component.redis-client
|
||||
(:require [asciinema.boundary.expiring-set :as exp-set]
|
||||
[clj-time.core :as t]
|
||||
[clj-time.local :as tl]
|
||||
[com.stuartsierra.component :as component]
|
||||
[taoensso.carmine :as car]))
|
||||
|
||||
(defrecord RedisClient [host port]
|
||||
component/Lifecycle
|
||||
(start [component]
|
||||
(if (:listener component)
|
||||
component
|
||||
(let [conn {:pool {} :spec {:host host :port port}}]
|
||||
(assoc component :conn conn))))
|
||||
(stop [component]
|
||||
(if (:conn component)
|
||||
(dissoc component :conn)
|
||||
component))
|
||||
|
||||
exp-set/ExpiringSet
|
||||
(conj! [this value expires-at]
|
||||
(let [seconds (t/in-seconds (t/interval (tl/local-now) expires-at))]
|
||||
(car/wcar (:conn this) (car/setex value seconds true))))
|
||||
(contains? [this value]
|
||||
(car/as-bool (car/wcar (:conn this) (car/exists value)))))
|
||||
|
||||
(defn redis-client [{:keys [host port]}]
|
||||
(->RedisClient host port))
|
Loading…
Reference in New Issue