/** * Reads cache entry. * * @param string $key Cache key name * @param boolean $nostore Enable to skip in-memory store * * @return mixed Cached value */ private function read_record($key, $nostore = false) { if (!$this->db) { return null; } if ($this->type != 'db') { $this->load_index(); // Consistency check (#1490390) if (!in_array($key, $this->index)) { // we always check if the key exist in the index // to have data in consistent state. Keeping the index consistent // is needed for keys delete operation when we delete all keys or by prefix. } else { $ckey = $this->ckey($key); if ($this->type == 'memcache') { $data = $this->db->get($ckey); } else { if ($this->type == 'apc') { $data = apc_fetch($ckey); } } if ($this->debug) { $this->debug('get', $ckey, $data); } } if ($data) { $md5sum = md5($data); $data = $this->unserialize($data); if ($nostore) { return $data; } $this->cache_sums[$key] = $md5sum; $this->cache[$key] = $data; } else { $this->cache[$key] = null; } } else { $sql_result = $this->db->limitquery("SELECT `data`, `cache_key`" . " FROM {$this->table}" . " WHERE `user_id` = ? AND `cache_key` = ?" . " ORDER BY `created` DESC", 0, 1, $this->userid, $this->prefix . '.' . $key); if ($sql_arr = $this->db->fetch_assoc($sql_result)) { $key = substr($sql_arr['cache_key'], strlen($this->prefix) + 1); $md5sum = $sql_arr['data'] ? md5($sql_arr['data']) : null; if ($sql_arr['data']) { $data = $this->unserialize($sql_arr['data']); } if ($nostore) { return $data; } $this->cache[$key] = $data; $this->cache_sums[$key] = $md5sum; } else { $this->cache[$key] = null; } } return $this->cache[$key]; }
/** * Reads cache entry. * * @param string $key Cache key name * @param boolean $nostore Enable to skip in-memory store * * @return mixed Cached value */ private function read_record($key, $nostore = false) { if (!$this->db) { return null; } if ($this->type != 'db') { if ($this->type == 'memcache') { $data = $this->db->get($this->ckey($key)); } else { if ($this->type == 'apc') { $data = apc_fetch($this->ckey($key)); } } if ($data) { $md5sum = md5($data); $data = $this->unserialize($data); if ($nostore) { return $data; } $this->cache_sums[$key] = $md5sum; $this->cache[$key] = $data; } else { $this->cache[$key] = null; } } else { $sql_result = $this->db->limitquery("SELECT data, cache_key" . " FROM " . $this->table . " WHERE user_id = ?" . " AND cache_key = ?" . " ORDER BY created DESC", 0, 1, $this->userid, $this->prefix . '.' . $key); if ($sql_arr = $this->db->fetch_assoc($sql_result)) { $key = substr($sql_arr['cache_key'], strlen($this->prefix) + 1); $md5sum = $sql_arr['data'] ? md5($sql_arr['data']) : null; if ($sql_arr['data']) { $data = $this->unserialize($sql_arr['data']); } if ($nostore) { return $data; } $this->cache[$key] = $data; $this->cache_sums[$key] = $md5sum; } else { $this->cache[$key] = null; } } return $this->cache[$key]; }
/** * Reads cache entry. * * @param string $key Cache key name * @param boolean $nostore Enable to skip in-memory store * * @return mixed Cached value */ private function read_record($key, $nostore = false) { if (!$this->db) { return null; } if ($this->type != 'db') { if ($this->type == 'memcache') { $data = $this->db->get($this->ckey($key)); } else { if ($this->type == 'apc') { $data = apc_fetch($this->ckey($key)); } } if ($data) { $md5sum = md5($data); $data = $this->unserialize($data); if ($nostore) { return $data; } $this->cache_sums[$key] = $md5sum; $this->cache[$key] = $data; } else { $this->cache[$key] = null; } } else { $sql_result = $this->db->limitquery("SELECT `data`, `cache_key`" . " FROM {$this->table}" . " WHERE `cache_key` = ?" . " ORDER BY `created` DESC", 0, 1, $this->prefix . '.' . $key); if ($sql_arr = $this->db->fetch_assoc($sql_result)) { $md5sum = $sql_arr['data'] ? md5($sql_arr['data']) : null; if ($sql_arr['data']) { $data = $this->unserialize($sql_arr['data']); } if ($nostore) { return $data; } $this->cache[$key] = $data; $this->cache_sums[$key] = $md5sum; } else { $this->cache[$key] = null; } } return $this->cache[$key]; }