Merge branch 'master' into develop
This commit is contained in:
commit
15887af961
|
@ -79,6 +79,9 @@ protected static function factory($driver)
|
||||||
case 'database':
|
case 'database':
|
||||||
return new Cache\Drivers\Database(Config::get('cache.key'));
|
return new Cache\Drivers\Database(Config::get('cache.key'));
|
||||||
|
|
||||||
|
case 'wincache':
|
||||||
|
return new Cache\Drivers\WinCache(Config::get('cache.key'));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \Exception("Cache driver {$driver} is not supported.");
|
throw new \Exception("Cache driver {$driver} is not supported.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php namespace Laravel\Cache\Drivers;
|
||||||
|
|
||||||
|
class WinCache extends Driver {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cache key from the cache configuration file.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $key;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new WinCache cache driver instance.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct($key)
|
||||||
|
{
|
||||||
|
$this->key = $key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if an item exists in the cache.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function has($key)
|
||||||
|
{
|
||||||
|
return ( ! is_null($this->get($key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve an item from the cache driver.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
protected function retrieve($key)
|
||||||
|
{
|
||||||
|
if (($cache = wincache_ucache_get($this->key.$key)) !== false)
|
||||||
|
{
|
||||||
|
return $cache;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an item to the cache for a given number of minutes.
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* // Put an item in the cache for 15 minutes
|
||||||
|
* Cache::put('name', 'Taylor', 15);
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @param int $minutes
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function put($key, $value, $minutes)
|
||||||
|
{
|
||||||
|
wincache_ucache_add($this->key.$key, $value, $minutes * 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write an item to the cache that lasts forever.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param mixed $value
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function forever($key, $value)
|
||||||
|
{
|
||||||
|
return $this->put($key, $value, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an item from the cache.
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function forget($key)
|
||||||
|
{
|
||||||
|
wincache_ucache_delete($this->key.$key);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue