protected function writeData($key, $value, $ttl)
    {
        if (!is_numeric($ttl) || $ttl < 0)
            throw new CacheException('TTL invalid: '. $ttl);

        if ($ttl == 0)
            $expiration = "datetime('now', '+100 years')"; // This will make the cache expire after you die, so it's effectively forever.
        else
            $expiration = "datetime('now', '+{$ttl} seconds')";

        return $this->db->queryExec("INSERT OR REPLACE INTO cache (key, value, expire) VALUES ('" . $this->key($key) . "', '".
                                                                                        sqlite_escape_string($value) . "',".
                                                                                        "{$expiration})");
    }