apc.php 1.47 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 (($cache = apc_fetch($this->key.$key)) !== false)
Taylor Otwell committed
43
		{
44
			return $cache;
Taylor Otwell committed
45
		}
Taylor Otwell committed
46 47
	}

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

Taylor Otwell committed
66
	/**
67 68 69 70 71 72 73 74 75 76 77 78
	 * 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);
	}

	/**
Taylor Otwell committed
79 80 81 82 83
	 * Delete an item from the cache.
	 *
	 * @param  string  $key
	 * @return void
	 */
Taylor Otwell committed
84 85
	public function forget($key)
	{
86
		apc_delete($this->key.$key);
Taylor Otwell committed
87 88 89
	}

}