Next: , Previous: Getting Started, Up: Tutorial


2.3 The Store Root

What values live between lisp sessions is called liveness. Liveness in a store is determined by whether the value can be reached from the root of the store. The root is a special BTree in which other BTrees and lisp values can be stored. This BTree has a special interface through the store controller. (There is a second root BTree called the class root which will be discussed later.)

You can put something into the root object by

     (add-to-root "my key" "my value")
     => "my value"

and get things out via

     (get-from-root "my key")
     => "my value"
     => T

The second value indicates whether the key was found. This is important if your key-value pair can have nil as a value.

You can perform other basic operations as well.

     (root-existsp "my key")
     => T
     (remove-from-root "my key")
     => T
     (get-from-root "my key")
     => NIL
     => NIL

To access all the objects in the root, the simplest way is to simply call map-root with a function to apply to each key-value pair.

     (map-root
       (lambda (k v)
          (format t "key: ~A value:~A~%" k v)))

You can also access the root object directly.

     (controller-root *store-controller*)
     => #<DB-BDB::BDB-BTREE  #x10e86042>

It is an instance of a class "btree"; see Persistent BTrees.