<commit_before>(ns carmine.ring
  "Carmine-backed Ring session store. Adapted from clj-redis-session."
  (:require [ring.middleware.session.store :as session-store]
            [carmine.core :as carmine])
  (:import  [java.util UUID]))

(defn new-session-key [prefix] (str prefix ":" (str (UUID/randomUUID))))

(defmacro wc [& body] `(carmine.core/with-conn ~'pool ~'spec ~@body))

(defrecord CarmineSessionStore [pool spec prefix expiration]
  session-store/SessionStore
  (read-session   [_ key] (or (when key (wc (carmine/get key))) {}))
  (delete-session [_ key] (wc (carmine/del key)) nil)
  (write-session  [_ key data]
    (let [key (or key (new-session-key prefix))]
      (if expiration
        (wc (carmine/setex key expiration data))
        (wc (carmine/set key data)))
      key)))

(defn make-carmine-store
  "Create and return a Carmine-backed Ring SessionStore. Use 'expiration-secs'
  to specify how long session data will survive after last write. When nil,
  sessions will never expire."
  [& {:keys [connection-pool connection-spec key-prefix expiration-secs]
      :or   {key-prefix       "carmine-session"
             expiration-secs  (str #=(* 60 60 24 30))}}]
  (CarmineSessionStore. connection-pool connection-spec
                        key-prefix (str expiration-secs)))<commit_msg>Removed unnecessary double 'str'<commit_after>(ns carmine.ring
  "Carmine-backed Ring session store. Adapted from clj-redis-session."
  (:require [ring.middleware.session.store :as session-store]
            [carmine.core :as carmine])
  (:import  [java.util UUID]))

(defn new-session-key [prefix] (str prefix ":" (UUID/randomUUID)))

(defmacro wc [& body] `(carmine.core/with-conn ~'pool ~'spec ~@body))

(defrecord CarmineSessionStore [pool spec prefix expiration]
  session-store/SessionStore
  (read-session   [_ key] (or (when key (wc (carmine/get key))) {}))
  (delete-session [_ key] (wc (carmine/del key)) nil)
  (write-session  [_ key data]
    (let [key (or key (new-session-key prefix))]
      (if expiration
        (wc (carmine/setex key expiration data))
        (wc (carmine/set key data)))
      key)))

(defn make-carmine-store
  "Create and return a Carmine-backed Ring SessionStore. Use 'expiration-secs'
  to specify how long session data will survive after last write. When nil,
  sessions will never expire."
  [& {:keys [connection-pool connection-spec key-prefix expiration-secs]
      :or   {key-prefix       "carmine-session"
             expiration-secs  (str #=(* 60 60 24 30))}}]
  (CarmineSessionStore. connection-pool connection-spec
                        key-prefix (str expiration-secs)))
{'fraction_non_alphanumeric': 0.13282732447817835, 'fraction_numerical': 0.0060721062618595825, 'mean_word_length': 3.286178861788618, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3701821', 'n_tokens_mistral': 893, 'n_tokens_neox': 848, 'n_words': 247}