26 Sessions
(require koyo/session) | package: koyo-lib |
This module exposes a component for storing and retrieving data from a browser session.
parameter
(current-session-manager) → (or/c #f session-manager?)
(current-session-manager sessions) → void? sessions : (or/c #f session-manager?)
Functions session-ref, session-set!, session-update! and session-remove! use this parameter under the hood to locate the manager.
The parameter is installed by wrap-session.
parameter
(current-session-id) → (or/c #f non-empty-string?)
(current-session-id session-id) → void? session-id : (or/c #f non-empty-string?)
procedure
(session-manager? v) → boolean?
v : any/c
procedure
(make-session-manager-factory #:cookie-name cookie-name [ #:cookie-path cookie-path #:cookie-secure? cookie-secure? #:cookie-http-only? cookie-http-only? #:cookie-same-site cookie-same-site] #:shelf-life shelf-life #:secret-key secret-key #:store store) → (-> session-manager?) cookie-name : non-empty-string? cookie-path : path-string? = "/" cookie-secure? : boolean? = #t cookie-http-only? : boolean? = #t cookie-same-site : (or/c 'lax 'strict) = 'strict shelf-life : exact-positive-integer? secret-key : bytes? store : session-store?
procedure
(session-ref k) → any/c
k : symbol? (session-ref k d) → any/c k : symbol? d : any/c
procedure
(session-manager-ref sm k) → any/c
sm : session-manager? k : symbol? (session-manager-ref sm k d) → any/c sm : session-manager? k : symbol? d : any/c
procedure
(session-set! k v) → void?
k : symbol? v : serializable?
procedure
(session-manager-set! sm k v) → void?
sm : session-manager? k : symbol? v : serializable?
procedure
(session-update! k p) → serializable?
k : symbol? p : (-> any/c serializable?) (session-update! k p d) → serializable? k : symbol? p : (-> any/c serializable?) d : any/c
procedure
(session-manager-update! sm k p) → serializable?
sm : session-manager? k : symbol? p : (-> any/c serializable?) (session-manager-update! sm k p d) → serializable? sm : session-manager? k : symbol? p : (-> any/c serializable?) d : any/c
procedure
(session-remove! k) → void?
k : symbol?
procedure
(session-manager-remove! sm k) → void?
sm : session-manager? k : symbol?
procedure
((wrap-session sm) handler) → (-> request? any/c ... response?)
sm : session-manager? handler : procedure?
If the current visitor doesn’t have a session cookie then a new one is generated and added to the response.
Each session’s lifetime is extended with every page load.
26.1 Session Stores
Session stores decide how session data is stored.
procedure
(session-store? v) → boolean?
v : any/c
procedure
v : any/c
procedure
(make-memory-session-store [ #:ttl ttl #:file-path path]) → session-store? ttl : exact-positive-integer? = (* 7 86400) path : path-string? = (make-temporary-file)
The #:ttl argument controls how many seconds to wait before removing stale sessions.
26.1.1 PostgreSQL Session Store
(require koyo/session/postgres) | package: koyo-lib |
This module provides a session store backed by PostgreSQL tables.
procedure
(postgres-session-store? v) → boolean?
v : any/c
procedure
(make-postgres-session-store database #:ttl exact-positive-integer?) → session-store? database : database? exact-positive-integer? : (* 7 86400)
The #:ttl argument determines how long sessions are kept around for.
Added in version 0.25 of package koyo-lib.