Elgg\Cache\Pool::get PHP Method

get() public method

Fetches a value from the cache, with the option of calculating on miss
public get ( string | integer $key, callable $callback = null, mixed $default = null ) : mixed
$key string | integer A plain string ID for the cache entry
$callback callable Logic for calculating the cache entry on miss
$default mixed Default value returned if the value is missing and no callback is provided
return mixed The cache value or the $default if no value and no callable
    public function get($key, callable $callback = null, $default = null);

Usage Example

Ejemplo n.º 1
0
 /**
  * Get the value of a datalist element.
  * 
  * Plugin authors should use elgg_get_config() and pass null for the site GUID.
  *
  * @internal Datalists are stored in the datalist table.
  *
  * @tip Use datalists to store information common to a full installation.
  *
  * @param string $name The name of the datalist
  * @return string|null|false String if value exists, null if doesn't, false on error
  * @access private
  */
 function get($name)
 {
     $name = trim($name);
     if (!$this->validateName($name)) {
         return false;
     }
     return $this->cache->get($name, function () use($name) {
         $escaped_name = $this->db->sanitizeString($name);
         $result = $this->db->getDataRow("SELECT * FROM {$this->table} WHERE name = '{$escaped_name}'");
         return $result ? $result->value : null;
     });
 }
All Usage Examples Of Elgg\Cache\Pool::get