From 334bb6b3537f9a613738041b68de2487dd59a5c1 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 3 Jan 2022 17:26:32 -0500 Subject: [PATCH] minor performance enhancements to read-session and write-session --- src/aging_session/core.clj | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/aging_session/core.clj b/src/aging_session/core.clj index 9c3d7ba..f3d6cf4 100644 --- a/src/aging_session/core.clj +++ b/src/aging_session/core.clj @@ -52,7 +52,7 @@ (let [session-map (sweep-entry session-map ttl key)] (if (and refresh-on-read? (contains? session-map key)) - (assoc-in session-map [key :timestamp] (now)) + (update session-map key assoc :timestamp (now)) ; note: performs faster than assoc-in session-map))) (defn- process-write-entry @@ -64,7 +64,7 @@ ; when not refreshing-on-write, we only need to update the entry value if there is an existing entry. otherwise, ; it is of course a brand new entry (if (contains? session-map key) - (assoc-in session-map [key :value] data) + (update session-map key assoc :value data) ; note: performs faster than assoc-in (assoc session-map key (new-entry data))))) (defprotocol AgingStore @@ -87,7 +87,9 @@ (when (contains? @session-atom key) (let [session-map (swap! session-atom process-read-entry ttl key refresh-on-read)] (if (contains? session-map key) - (get-in session-map [key :value]) + (-> session-map ; note: performs faster than get-in + (get key) + (get :value)) ; TODO: notify expiry listener about expired 'key' here ))))