From 38c6a37d5961f9a02ce7eeed60409e1b8cc2b2cc Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 2 Jan 2022 16:19:34 -0500 Subject: [PATCH] optimization for when the session entry doesn't exist an easy and very significant performance boost for this scenario ... --- src/aging_session/memory.clj | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/aging_session/memory.clj b/src/aging_session/memory.clj index e683fd6..0fa5302 100644 --- a/src/aging_session/memory.clj +++ b/src/aging_session/memory.clj @@ -56,11 +56,12 @@ SessionStore (read-session [_ key] - (let [ts (now)] - (swap! session-map sweep-entry ts ttl key) - (when (and refresh-on-read (contains? @session-map key)) - (swap! session-map assoc-in [key :timestamp] ts)) - (get-in @session-map [key :value]))) + (when (contains? @session-map key) + (let [ts (now)] + (swap! session-map sweep-entry ts ttl key) + (when (and refresh-on-read (contains? @session-map key)) + (swap! session-map assoc-in [key :timestamp] ts)) + (get-in @session-map [key :value])))) (write-session [_ key data] (let [key (or key (str (UUID/randomUUID)))]