/** * Tests saving data. */ public function testSaveData() { $object = $this->saveObject(); $this->assertSame($object, $this->cache->get(self::CACHE_KEY)); // Saving using one way ObjectCache::set(self::CACHE_KEY, $object); $this->assertSame($object, $this->cache->get(self::CACHE_KEY)); // Saving using the other way $this->cache->{self::CACHE_KEY} = $object; $this->assertSame($object, $this->cache->get(self::CACHE_KEY)); $this->cache->clear(); }
/** * Run query and return array of results * * @param string $error_message * @param boolean $die_on_error * @return array */ function run($error_message = '', $die_on_error = true) { $q = $this->get_query(); if ($this->cache_lifespan) { $cache = new ObjectCache('db_selector_cache_' . get_current_db_connection_name() . '_' . $q, $this->cache_lifespan); $results =& $cache->fetch(); if (false !== $results) { return $results; } } $results = array(); $r = db_query($q, $error_message, $die_on_error); if ($r) { while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { $results[] = $row; } mysql_free_result($r); } if (!empty($cache)) { $cache->set($results); } return $results; }
/** @access private */ function _persist_filename($value, $original = null, $display_name = null) { $cache_id = uniqid('upload_' . mt_rand() . '_', true); $cache = new ObjectCache($cache_id, '360'); $store = new stdClass(); $store->value = $value; $store->path_to_original = $original; $store->display_name = $display_name; $cache->set($store); return $cache_id; }
final function create_nonce() { $nonce_key = md5(uniqid(mt_rand(), true)); $update_data['config'] = $this->get_config(); $update_data['model'] = $this->model_name; $update = new ObjectCache($nonce_key); $update->set($update_data); return $nonce_key; }
function _get_version_info() { $version = $this->get_current_version_id(); $cache = new ObjectCache(); $cache->init('ReasonVersionCheckCache', 86400); // cache for 1 day $obj = $cache->fetch(); if(empty($obj) || !$obj->get_data() || $obj->get_version() != $version) { $obj = new ReasonVersionCheckData; $obj->set_data($this->_fetch_response_from_remote_server($version)); $obj->set_version($version); $cache->set($obj); } return $obj->get_data(); }
public static function loadByEmail($email) { $db = Db::instance(); $query = sprintf("SELECT * FROM user WHERE email = '%s'", $email); $result = $db->lookup($query); if (!mysql_num_rows($result)) { return null; } else { $row = mysql_fetch_assoc($result); $obj = new User($row); ObjectCache::set('User', $row['id'], $obj); return $obj; } }
/** * Runs one query for the ES. If type is empty, it uses the first type by default. * This is often called without paramaters in code for front end stuff. * <code> * $es = new entity_selector( $site_id ); * $es->add_type( $type_id ); * $results = $es->run_one(); * </code> * @param int $type type_id (or blank for default) * @param string $status Either Live, Pending, Archived, or All ... (optional) * @param string $error optional error message * @return array */ function run_one($type = '', $status = 'Live', $error = 'run_one error') { if (!$type) { if (isset($this->type[0]) && $this->type[0]) { $type = $this->type[0]; } else { trigger_error('Entity Selector: No type available. Try using the method add_type($type_id) before calling run_one(), or call run_one() with the type id as the first argument.'); return array(); } } $query = $this->get_one_query($type, $status); $factory =& $this->get_entity_factory(); if ($this->cache_lifespan) { $factory_class = $factory ? get_class($factory) : ''; //echo '<p>caching '.$this->cache_lifespan.' secs</p>'; $cache = new ObjectCache('entity_selector_cache_' . get_current_db_connection_name() . '_' . $this->_enable_multivalue_results . '_' . $factory_class . '_' . $query, $this->cache_lifespan); $results =& $cache->fetch(); if (false !== $results) { //echo '<p>Cache hit</p>'; return $results; } //echo '<p>Cache miss</p>'; } $results = array(); $r = db_query($query, $this->description . ': ' . $error); while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) { //pray ($row); if ($this->_enable_multivalue_results && isset($results[$row['id']])) { $prev_val = $new_val = $key = $val = ''; $e = $results[$row['id']]; foreach ($row as $key => $val) { $cur_value = $e->get_value($key); if (is_array($cur_value)) { if (!in_array($val, $cur_value) && !empty($val)) { $cur_value[] = $val; $e->set_value($key, $cur_value); } } elseif ($cur_value != $val && !empty($val)) { if (empty($cur_value)) { $e->set_value($key, $val); } else { $e->set_value($key, array($cur_value, $val)); } } } } else { if ($factory) { $e = $factory->get_entity($row); } else { $e = new entity($row['id']); } $e->_values = $row; } $results[$row['id']] = $e; } mysql_free_result($r); if (!empty($cache)) { $cache->set($results); } return $results; }