put() public method

This is useful when the value was calculated by some out-of-band means. For example, when a list of rows is fetched from the database, you can prime the cache for each individual result.
public put ( string | integer $key, mixed $value ) : void
$key string | integer A plain string ID for the cache entry
$value mixed The cache value
return void
Example #1
0
 /**
  * Load entire datalist in memory.
  * 
  * This could cause OOM problems if the datalists table is large.
  * 
  * @todo make a list of datalists that we want to get in one grab
  * 
  * @return array
  * @access private
  */
 function loadAll()
 {
     $result = $this->db->getData("SELECT * FROM {$this->table}");
     $map = array();
     if (is_array($result)) {
         foreach ($result as $row) {
             $map[$row->name] = $row->value;
             $this->cache->put($row->name, $row->value);
         }
     }
     return $map;
 }
 /**
  * Save URL data to the database
  *
  * @param string $url  URL
  * @param array  $data Data
  * @return boolean
  */
 public function save($url, $data = false)
 {
     if (!$url) {
         return false;
     }
     $dbprefix = elgg_get_config('dbprefix');
     $result = insert_data("\n\t\t\tINSERT INTO {$dbprefix}scraper_data\n\t\t\tSET url = :url,\n\t\t\t    hash = :hash,\n\t\t\t\tdata = :data\n\t\t\tON DUPLICATE KEY UPDATE\n\t\t\t    data = :data\n\t\t", [':url' => (string) $url, ':data' => serialize($data), ':hash' => sha1($url)]);
     if ($result) {
         $this->cache->put(sha1($url), $data);
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Cache a reference to this plugin by its ID
  * 
  * @param \ElggPlugin $plugin
  * 
  * @access private
  */
 function cache(\ElggPlugin $plugin)
 {
     $this->plugins_by_id->put($plugin->getID(), $plugin);
 }