Commit 9454927b authored by Taylor Otwell's avatar Taylor Otwell

Added Cache::maybe method.

parent 1d96b968
......@@ -50,6 +50,30 @@ class Cache {
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.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment