2011-09-14 20:16:13 -05:00
|
|
|
<?php namespace Laravel\Cache\Drivers;
|
2011-08-18 19:56:29 -05:00
|
|
|
|
|
|
|
|
class APC extends Driver {
|
|
|
|
|
|
2011-08-26 21:42:04 -05:00
|
|
|
/**
|
|
|
|
|
* The cache key from the cache configuration file.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2011-10-12 21:55:05 -05:00
|
|
|
protected $key;
|
2011-08-26 21:42:04 -05:00
|
|
|
|
2011-08-24 22:51:32 -05:00
|
|
|
/**
|
|
|
|
|
* Create a new APC cache driver instance.
|
|
|
|
|
*
|
2011-09-20 23:14:09 -05:00
|
|
|
* @param string $key
|
2011-08-24 22:51:32 -05:00
|
|
|
* @return void
|
|
|
|
|
*/
|
2011-09-20 23:14:09 -05:00
|
|
|
public function __construct($key)
|
2011-08-24 22:51:32 -05:00
|
|
|
{
|
2011-08-26 21:42:04 -05:00
|
|
|
$this->key = $key;
|
2011-08-24 22:51:32 -05:00
|
|
|
}
|
|
|
|
|
|
2011-08-19 20:12:39 -05:00
|
|
|
/**
|
|
|
|
|
* Determine if an item exists in the cache.
|
|
|
|
|
*
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2011-08-18 19:56:29 -05:00
|
|
|
public function has($key)
|
|
|
|
|
{
|
|
|
|
|
return ( ! is_null($this->get($key)));
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 20:12:39 -05:00
|
|
|
/**
|
|
|
|
|
* Retrieve an item from the cache driver.
|
|
|
|
|
*
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
protected function retrieve($key)
|
2011-08-18 19:56:29 -05:00
|
|
|
{
|
2012-02-12 14:48:36 -06:00
|
|
|
if (($cache = apc_fetch($this->key.$key)) !== false)
|
2011-11-02 21:27:43 -05:00
|
|
|
{
|
2012-03-21 14:45:05 -05:00
|
|
|
return $cache;
|
2011-11-02 21:27:43 -05:00
|
|
|
}
|
2011-08-18 19:56:29 -05:00
|
|
|
}
|
|
|
|
|
|
2011-08-19 20:12:39 -05:00
|
|
|
/**
|
|
|
|
|
* Write an item to the cache for a given number of minutes.
|
|
|
|
|
*
|
2011-10-12 21:55:05 -05:00
|
|
|
* <code>
|
|
|
|
|
* // Put an item in the cache for 15 minutes
|
|
|
|
|
* Cache::put('name', 'Taylor', 15);
|
|
|
|
|
* </code>
|
|
|
|
|
*
|
2011-08-19 20:12:39 -05:00
|
|
|
* @param string $key
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
* @param int $minutes
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2011-08-18 19:56:29 -05:00
|
|
|
public function put($key, $value, $minutes)
|
|
|
|
|
{
|
2012-03-21 14:45:05 -05:00
|
|
|
apc_store($this->key.$key, $value, $minutes * 60);
|
2011-08-18 19:56:29 -05:00
|
|
|
}
|
|
|
|
|
|
2012-03-14 09:02:24 -05:00
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-19 20:12:39 -05:00
|
|
|
/**
|
|
|
|
|
* Delete an item from the cache.
|
|
|
|
|
*
|
|
|
|
|
* @param string $key
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2011-08-18 19:56:29 -05:00
|
|
|
public function forget($key)
|
|
|
|
|
{
|
2011-09-20 23:14:09 -05:00
|
|
|
apc_delete($this->key.$key);
|
2011-08-18 19:56:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|