better naming
This commit is contained in:
parent
baecdaf136
commit
65870439bd
|
@ -57,42 +57,42 @@
|
||||||
(read-timestamp [store key]
|
(read-timestamp [store key]
|
||||||
"Read a session from the store and return its timestamp. If no key exists, returns nil."))
|
"Read a session from the store and return its timestamp. If no key exists, returns nil."))
|
||||||
|
|
||||||
(defrecord MemoryAgingStore [session-map thread ttl refresh-on-write refresh-on-read op-counter op-threshold]
|
(defrecord MemoryAgingStore [session-atom thread ttl refresh-on-write refresh-on-read op-counter op-threshold]
|
||||||
AgingStore
|
AgingStore
|
||||||
(read-timestamp [_ key]
|
(read-timestamp [_ key]
|
||||||
(get-in @session-map [key :timestamp]))
|
(get-in @session-atom [key :timestamp]))
|
||||||
|
|
||||||
SessionStore
|
SessionStore
|
||||||
(read-session [_ key]
|
(read-session [_ key]
|
||||||
(when (contains? @session-map key)
|
(when (contains? @session-atom key)
|
||||||
(let []
|
(let []
|
||||||
(swap! session-map sweep-entry ttl key)
|
(swap! session-atom sweep-entry ttl key)
|
||||||
(when (and refresh-on-read (contains? @session-map key))
|
(when (and refresh-on-read (contains? @session-atom key))
|
||||||
(swap! session-map assoc-in [key :timestamp] (now)))
|
(swap! session-atom assoc-in [key :timestamp] (now)))
|
||||||
(get-in @session-map [key :value]))))
|
(get-in @session-atom [key :value]))))
|
||||||
|
|
||||||
(write-session [_ key data]
|
(write-session [_ key data]
|
||||||
(let [key (or key (unique-id))]
|
(let [key (or key (unique-id))]
|
||||||
(if op-threshold
|
(if op-threshold
|
||||||
(swap! op-counter inc))
|
(swap! op-counter inc))
|
||||||
(if refresh-on-write
|
(if refresh-on-write
|
||||||
(swap! session-map assoc key (new-entry data))
|
(swap! session-atom assoc key (new-entry data))
|
||||||
(swap! session-map write-entry key data))
|
(swap! session-atom write-entry key data))
|
||||||
key))
|
key))
|
||||||
|
|
||||||
(delete-session [_ key]
|
(delete-session [_ key]
|
||||||
(swap! session-map dissoc key)
|
(swap! session-atom dissoc key)
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
(defn- sweeper-thread
|
(defn- sweeper-thread
|
||||||
"Sweeper thread that watches the session and cleans it."
|
"Sweeper thread that watches the session and cleans it."
|
||||||
[session-map ttl op-counter op-threshold sweep-interval]
|
[session-atom ttl op-counter op-threshold sweep-interval]
|
||||||
(loop []
|
(loop []
|
||||||
(if op-threshold
|
(if op-threshold
|
||||||
(when (>= @op-counter op-threshold)
|
(when (>= @op-counter op-threshold)
|
||||||
(swap! session-map sweep-session ttl)
|
(swap! session-atom sweep-session ttl)
|
||||||
(reset! op-counter 0))
|
(reset! op-counter 0))
|
||||||
(swap! session-map sweep-session ttl))
|
(swap! session-atom sweep-session ttl))
|
||||||
(Thread/sleep sweep-interval)
|
(Thread/sleep sweep-interval)
|
||||||
(recur)))
|
(recur)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue