+ /**
+ * Saves the database from memory to disk
+ *
+ * @throws IOException the datastore is not writable
+ */
+ private function writeDB()
+ {
+ if (is_file($this->_datastore) && !is_writeable($this->_datastore)) {
+ // The datastore exists but is not writeable
+ throw new IOException($this->_datastore);
+ } else if (!is_file($this->_datastore) && !is_writeable(dirname($this->_datastore))) {
+ // The datastore does not exist and its parent directory is not writeable
+ throw new IOException(dirname($this->_datastore));
+ }
+
+ file_put_contents(
+ $this->_datastore,
+ self::$phpPrefix.base64_encode(gzdeflate(serialize($this->_links))).self::$phpSuffix
+ );
+
+ }
+