Added Cache::maybe method.
This commit is contained in:
parent
1d96b96828
commit
9454927bd3
|
@ -50,6 +50,30 @@ public static function get($key, $default = null, $driver = null)
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an item from the cache. If it doesn't exist, store the default value
|
||||||
|
* in the cache and return it.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $default
|
||||||
|
* @param int $minutes
|
||||||
|
* @param string $driver
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function maybe($key, $default, $minutes, $driver = null)
|
||||||
|
{
|
||||||
|
if ( ! is_null($item = static::get($key)))
|
||||||
|
{
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
$default = is_callable($default) ? call_user_func($default) : $default;
|
||||||
|
|
||||||
|
static::driver($driver)->put($key, $default, $minutes);
|
||||||
|
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pass all other methods to the default driver.
|
* Pass all other methods to the default driver.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue