Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /** @access private */
 function _restore_filename($cache_id)
 {
     $cache = new ObjectCache($cache_id, '360');
     $store =& $cache->fetch();
     if (!$store) {
         return array(null, null, null);
     }
     return array($store->value, $store->path_to_original, $store->display_name);
 }
Exemplo n.º 3
0
 /**
  * Using the data_id, retrieve the data from our local cache
  */
 final function get_local_data()
 {
     $id = $this->get_data_id();
     $cache = new ObjectCache($id, 999999999);
     // we use an enormous expiration ... we want to get whatever exists.
     $data =& $cache->fetch();
     return $data;
 }
Exemplo n.º 4
0
<?php

/**
 * The sweeter tweet reader agent handles the background requests when given a proper nonce.
 */
require_once '../sweeter_tweet_reader.php';
if (isset($_REQUEST['sweeter_tweet_reader_nonce'])) {
    // retrieve the model and config from the nonce
    $sweet_tweet = new SweeterTweetReader();
    $update = new ObjectCache($_REQUEST['sweeter_tweet_reader_nonce'], 999999999);
    $data = $update->fetch();
    if (!empty($data)) {
        $sweet_tweet->set($data['model']);
        $sweet_tweet->config($data['config']);
        $sweet_tweet->update();
    }
    $update->clear();
}
Exemplo n.º 5
0
	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();
	}
Exemplo n.º 6
0
 /**
  * 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;
 }