lithium\storage\cache\adapter\XCache::clear()
Overrides
lithium\storage\cache\Adapter::clear()
Clears entire user-space cache by flushing it. All cache keys using the configuration but without honoring the scope are removed.
This method requires valid XCache admin credentials to be set when the adapter
was configured, due to the use of the xcache_clear_cache admin method. If the
xcache.admin.enable_auth
ini setting is set to Off
, no credentials required.
The behavior and result when removing a single key during this process fails is unknown.
Returns
booleantrue
on successful clearing, false
otherwise.
Source
public function clear() {
$admin = (ini_get('xcache.admin.enable_auth') === "On");
if ($admin && (!isset($this->_config['username']) || !isset($this->_config['password']))) {
return false;
}
$credentials = array();
if (isset($_SERVER['PHP_AUTH_USER'])) {
$credentials['username'] = $_SERVER['PHP_AUTH_USER'];
$_SERVER['PHP_AUTH_USER'] = $this->_config['username'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$credentials['password'] = $_SERVER['PHP_AUTH_PW'];
$_SERVER['PHP_AUTH_PW'] = $this->_config['pass'];
}
for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) {
if (xcache_clear_cache(XC_TYPE_VAR, $i) === false) {
return false;
}
}
if (isset($_SERVER['PHP_AUTH_USER'])) {
$_SERVER['PHP_AUTH_USER'] = $credentials['username'];
}
if (isset($_SERVER['PHP_AUTH_PW'])) {
$_SERVER['PHP_AUTH_PW'] = $credentials['password'];
}
return true;
}