 (def memory-sessions (ref {}))
 
 (defmethod read-session :memory
-  [id]
+  [repository id]
   (@memory-sessions id))
 
 (defmethod write-session :memory
-  [session]
+  [repository session]
   (dosync
     (alter memory-sessions
       assoc (session :id) session)))
 
 (defmethod destroy-session :memory
-  [session]
+  [repository session]
   (dosync
     (alter memory-sessions
       dissoc (session :id))))

(defn- assoc-expiry
  "Associate an :expires-at key with the session if the session repository
  contains the :expires key."
  [session]
  (if-let [expires (:expires *session-repo*)]
    (assoc session :expires-at (timestamp-after expires))
    session))


  (:use compojure.crypto)
  (:use clojure.contrib.except))

;; Override these mulitmethods to create your own session storage.
;; Uses the Compojure repository pattern.

(defmulti create-session
  "Create a new session map. Should not attempt to save the session."
  (fn [repository] (type repository)))

(defmulti read-session
  "Read in the session using the supplied data. Usually the data is a key used
  to find the session in a store."
  (fn [repository data] (type repository)))

(defmulti write-session
  "Write a new or existing session to the session store."
  (fn [repository session] (type repository)))

(defmulti destroy-session
  "Remove the session from the session store."
  (fn [repository session] (type repository)))

(defmulti session-cookie
  "Return the session data to be stored in the cookie. This is usually the
  session ID."
  (fn [repository new? session] (type repository)))

;; Default implementations of create-session and set-session-cookie

(defmethod create-session :default
  [repository]
  {:id (gen-uuid)})

(defmethod session-cookie :default
  [repository new? session]
  (if new?
    (session :id)))

