private function lookup_constituency($postcode) { $cache = cache::factory(); $cached = $cache->get('twfy' . $postcode); if (isset($cached) && $cached !== false && $cached != '') { return $cached; } else { if (COUNTRY_CODE_TLD == "uk") { $twfy = factory::create('twfy'); $twfy_constituency = $twfy->query('getConstituency', array('output' => 'php', 'postcode' => $postcode, 'future' => 'yes_please')); $twfy_constituency = unserialize($twfy_constituency); $success = $cache->set('twfy' . $postcode, $twfy_constituency); $twfy_constituency = array($twfy_constituency["name"]); } else { if (COUNTRY_CODE_TLD == "au") { $australian_postcode = factory::create("australian_postcode"); return $australian_postcode->lookup_constituency_names($postcode); } else { $success = false; } } if ($success && isset($twfy_constituency) && $twfy_constituency != '' && $twfy_constituency != false) { return $twfy_constituency; } else { return false; } } }
private function get_leaflet_count() { $return = 0; $cache = cache::factory(); $cached = $cache->get("total_leaflet_count"); if ($cached !== false && isset($cached)) { $return = $cached; } else { $leaflet = factory::create('leaflet'); $return = $leaflet->count(); $cache->set("total_leaflet_count", $return); } return $return; }
function lookup_constituency($postcode) { $cache = cache::factory(); $cached = $cache->get('twfy' . $postcode); if (isset($cached) && $cached !== false && $cached != '') { return $cached; } else { $twfy = factory::create('twfy'); $twfy_constituency = $twfy->query('getConstituency', array('output' => 'php', 'postcode' => $postcode, 'future' => 'yes_please')); $twfy_constituency = unserialize($twfy_constituency); $success = $cache->set('twfy' . $postcode, $twfy_constituency); if ($success && isset($twfy_constituency) && $twfy_constituency != '' && $twfy_constituency != false) { return $twfy_constituency; } else { return false; } } }
public function query_cached($class_name, $sql) { $return = false; //check the cache $cache = cache::factory(); $cached = $cache->get($sql, "search"); //try and get from cache, if not, get from database if (isset($cached) && $cached !== false) { $return = $cached; } else { $return = $this->query($class_name, $sql); //cache $cached = $cache->set($sql, $return, "search"); if ($cached == false) { trigger_error("Failed to cache database call"); } } return $return; }
function safe_scrape_cached($url) { $cache = cache::factory(); $cached = $cache->get($url); if (isset($cached) && $cached !== false) { return $cached; } else { $page = safe_scrape($url); $cache->set($url, $page, "safe_scrape"); return $page; } }
public function execute_cached($sql) { $return = null; $cache = cache::factory(); $cached = $cache->get($key, "execute"); //if we have something in the cache, grab that, if not do the query as normal if (isset($cached) && $cached !== false) { $return = $cached; } else { $return = $this->execute($sql); $cached = $cache->set($key, $return, "execute"); } return $return; }
public function count_cached() { $return = null; $cache = cache::factory(); $key = serialize($this); $cached = $cache->get($key, "count"); //if we have something in the cache, grab that, if not do the query as normal if (isset($cached) && $cached !== false) { $return = $cached; } else { $return = $this->count(); } return $return; }