Commit aaae1acb authored by Taylor Otwell's avatar Taylor Otwell

Refactor cache class. Fix driver instantiation bug. Allow closures as default parameter.

parent 715bed74
......@@ -17,19 +17,39 @@ class Cache {
*/
public static function driver($driver = null)
{
if ( ! array_key_exists($driver, static::$drivers))
if (is_null($driver))
{
if (is_null($driver))
{
$driver = Config::get('cache.driver');
}
$driver = Config::get('cache.driver');
}
if ( ! array_key_exists($driver, static::$drivers))
{
static::$drivers[$driver] = Cache\Factory::make($driver);
}
return static::$drivers[$driver];
}
/**
* Get an item from the cache.
*
* @param string $key
* @param mixed $default
* @param string $driver
* @return mixed
*/
public static function get($key, $default = null, $driver = null)
{
$item = static::driver($driver)->get($key);
if (is_null($item))
{
return is_callable($default) ? call_user_func($default) : $default;
}
return $item;
}
/**
* 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