apc.php 1.25 KB
Newer Older
1
<?php namespace Laravel\Cache\Drivers;
Taylor Otwell committed
2 3 4

class APC extends Driver {

Taylor Otwell committed
5
	/**
6 7 8 9
	 * The cache key from the cache configuration file.
	 *
	 * @var string
	 */
10
	protected $key;
11 12

	/**
13 14
	 * Create a new APC cache driver instance.
	 *
15
	 * @param  string  $key
16 17
	 * @return void
	 */
18
	public function __construct($key)
19
	{
20
		$this->key = $key;
21 22 23
	}

	/**
Taylor Otwell committed
24 25 26 27 28
	 * Determine if an item exists in the cache.
	 *
	 * @param  string  $key
	 * @return bool
	 */
Taylor Otwell committed
29 30 31 32 33
	public function has($key)
	{
		return ( ! is_null($this->get($key)));
	}

Taylor Otwell committed
34 35 36 37 38 39 40
	/**
	 * Retrieve an item from the cache driver.
	 *
	 * @param  string  $key
	 * @return mixed
	 */
	protected function retrieve($key)
Taylor Otwell committed
41
	{
42
		if ( ! is_null($cache = apc_fetch($this->key.$key))) return $cache;
Taylor Otwell committed
43 44
	}

Taylor Otwell committed
45 46 47
	/**
	 * Write an item to the cache for a given number of minutes.
	 *
48 49 50 51 52
	 * <code>
	 *		// Put an item in the cache for 15 minutes
	 *		Cache::put('name', 'Taylor', 15);
	 * </code>
	 *
Taylor Otwell committed
53 54 55 56 57
	 * @param  string  $key
	 * @param  mixed   $value
	 * @param  int     $minutes
	 * @return void
	 */
Taylor Otwell committed
58 59
	public function put($key, $value, $minutes)
	{
60
		apc_store($this->key.$key, $value, $minutes * 60);
Taylor Otwell committed
61 62
	}

Taylor Otwell committed
63 64 65 66 67 68
	/**
	 * Delete an item from the cache.
	 *
	 * @param  string  $key
	 * @return void
	 */
Taylor Otwell committed
69 70
	public function forget($key)
	{
71
		apc_delete($this->key.$key);
Taylor Otwell committed
72 73 74
	}

}