Removed dep on API
[ninja.git] / system / libraries / drivers / Cache / Xcache.php
blobbacd1b687cc95344f067e59e9117d8d77def08e9
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Xcache Cache driver.
5 * $Id: Xcache.php 3917 2009-01-21 03:06:22Z zombor $
7 * @package Cache
8 * @author Kohana Team
9 * @copyright (c) 2007-2008 Kohana Team
10 * @license http://kohanaphp.com/license.html
12 class Cache_Xcache_Driver implements Cache_Driver {
14 public function __construct()
16 if ( ! extension_loaded('xcache'))
17 throw new Kohana_Exception('cache.extension_not_loaded', 'xcache');
20 public function get($id)
22 if (xcache_isset($id))
23 return xcache_get($id);
25 return NULL;
28 public function set($id, $data, $tags, $lifetime)
30 count($tags) and Kohana::log('error', 'Cache: tags are unsupported by the Xcache driver');
32 return xcache_set($id, $data, $lifetime);
35 public function find($tag)
37 Kohana::log('error', 'Cache: tags are unsupported by the Xcache driver');
38 return FALSE;
41 public function delete($id, $tag = FALSE)
43 if ($tag !== FALSE)
45 Kohana::log('error', 'Cache: tags are unsupported by the Xcache driver');
46 return TRUE;
48 elseif ($id !== TRUE)
50 if (xcache_isset($id))
51 return xcache_unset($id);
53 return FALSE;
55 else
57 // Do the login
58 $this->auth();
59 $result = TRUE;
60 for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++)
62 if (xcache_clear_cache(XC_TYPE_VAR, $i) !== NULL)
64 $result = FALSE;
65 break;
69 // Undo the login
70 $this->auth(TRUE);
71 return $result;
74 return TRUE;
77 public function delete_expired()
79 return TRUE;
82 private function auth($reverse = FALSE)
84 static $backup = array();
86 $keys = array('PHP_AUTH_USER', 'PHP_AUTH_PW');
88 foreach ($keys as $key)
90 if ($reverse)
92 if (isset($backup[$key]))
94 $_SERVER[$key] = $backup[$key];
95 unset($backup[$key]);
97 else
99 unset($_SERVER[$key]);
102 else
104 $value = getenv($key);
106 if ( ! empty($value))
108 $backup[$key] = $value;
111 $_SERVER[$key] = Kohana::config('cache_xcache.'.$key);
116 } // End Cache Xcache Driver