/** * Check for previously cached results * * @param string|Query $query the search query * @return null|ResultSet null if no previously cached results */ public function getCachedResults($query) { // if cache is turned off, then don't bother looking up cache if ($this->should_cache_results == false) { return null; } $id = $this->getResultsID($query); return $this->cache->get($id); }
/** * Fetch list of databases * * @param bool $force_new get data from ebsco * @return array */ public function getDatabases($force_new = false) { $cache = new Cache(); $id = 'ebsco_databases'; if ($force_new == false) { // do we have it already? if (count($this->databases) > 0) { return $this->databases; } // check the cache $this->databases = $cache->get($id); if ($this->databases != null) { return $this->databases; } } // fetch 'em from ebsco $url = $this->host . '/Info?' . 'prof=' . $this->username . '&pwd=' . $this->password; $client = Factory::getHttpClient(); $response = $client->getUrl($url); $xml = new \DOMDocument(); $loaded = $xml->loadXML($response); if ($loaded == true) { $nodes = $xml->getElementsByTagName('db'); if ($nodes->length > 1) { foreach ($nodes as $db) { if ((string) $db->getAttribute('dbType') == 'Regular') { $id = (string) $db->getAttribute('shortName'); $name = (string) $db->getAttribute('longName'); $this->databases[$id] = $name; } } // cache 'em $cache->set($id, $this->databases); } } return $this->databases; }
/** * Look for any holdings data in the cache and add it to results */ public function injectHoldings() { // get the record ids for all search results $ids = $this->extractRecordIDs(); // only if there are actually records here if (count($ids) > 0) { // prefix the engine id for ($x = 0; $x < count($ids); $x++) { $ids[$x] = $this->config->getID() . "." . $ids[$x]; } // look for any of our items $cache = new Cache(); $cache_array = $cache->get($ids); foreach ($cache_array as $id => $data) { $holdings = unserialize($data); if (!$holdings instanceof Holdings) { throw new \Exception("cached item ({$id}) is not an instance of Holdings"); } // now associate this item with its corresponding result for ($x = 0; $x < count($this->records); $x++) { $search_result = $this->records[$x]; if ($this->config->getID() . "." . $search_result->xerxes_record->getRecordID() == $id) { $search_result->setHoldings($holdings); } $this->records[$x] = $search_result; } } } }