Skip to content

How to save data in a session

macourtney edited this page Sep 13, 2010 · 3 revisions

Added for version: 0.4
Updated for version: 0.7

Conjure automatically sends a cookie to every visitor to your server. If you want to save information for a specific visitor you can use the session store.

By default, the session store saves your data to a special table called ‘sessions’ in your database. To change the method for saving session data, update the session_config.clj file in the config directory. You can also use session_config.clj to change conjure to pass the session id back and forth through a parameter instead of a cookie. However, passing the session as a parameter may not be secure.

The session store uses key-value mapping for the data you wish to store. If you want to save the user-id to the session, you must save it under the :user-id key.

Before you can save data to the session store, you must use conjure.core.model.session-store.

To save a :user-id with value 1 to the session store use:

(save :user-id 1)

To retrieve the value of :user-id from the session store use:

(retrieve-value :user-id)

To retrieve all data saved in the session use:

(retrieve)

Retrieve will return all of the data in the session as a map.

To delete :user-id from the session store use:

(delete :user-id)

To delete all data in a session use:

(drop-session)

Allowed Data Types

Only certain data types can be saved to the database session store. The following types are allowed:

  • Characters
  • Floats
  • Integers
  • keywords
  • lists
  • maps
  • sets
  • strings
  • symbols
  • vectors
Clone this wiki locally