Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Hotfix/xcache empty namespace #3069

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 53 additions & 18 deletions library/Zend/Cache/Storage/Adapter/XCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ public function getAvailableSpace()
*/
public function clearByNamespace($namespace)
{
$namespace = (string) $namespace;
if ($namespace === '') {
throw new Exception\InvalidArgumentException('No namespace given');
}

$options = $this->getOptions();
$prefix = $namespace . $options->getNamespaceSeparator();

Expand All @@ -182,8 +187,14 @@ public function clearByNamespace($namespace)
*/
public function clearByPrefix($prefix)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator() . $prefix;
$prefix = (string) $prefix;
if ($prefix === '') {
throw new Exception\InvalidArgumentException('No prefix given');
}

$options = $this->getOptions();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator() . $prefix;

xcache_unset_by_prefix($prefix);
return true;
Expand Down Expand Up @@ -217,18 +228,35 @@ public function flush()
*/
public function getIterator()
{
$options = $this->getOptions();
$prefixL = strlen($options->getNamespace() . $options->getNamespaceSeparator());
$keys = array();

$options = $this->getOptions();
$namespace = $options->getNamespace();
$keys = array();

$this->initAdminAuth();
$cnt = xcache_count(XC_TYPE_VAR);
for ($i=0; $i < $cnt; $i++) {
$list = xcache_list(XC_TYPE_VAR, $i);
foreach ($list['cache_list'] as & $item) {
$keys[] = substr($item['name'], $prefixL);

if ($namespace === '') {
$cnt = xcache_count(XC_TYPE_VAR);
for ($i=0; $i < $cnt; $i++) {
$list = xcache_list(XC_TYPE_VAR, $i);
foreach ($list['cache_list'] as & $item) {
$keys[] = $item['name'];
}
}
} else {

$prefix = $namespace . $options->getNamespaceSeparator();
$prefixL = strlen($prefix);

$cnt = xcache_count(XC_TYPE_VAR);
for ($i=0; $i < $cnt; $i++) {
$list = xcache_list(XC_TYPE_VAR, $i);
foreach ($list['cache_list'] as & $item) {
$keys[] = substr($item['name'], $prefixL);
}
}
}

$this->resetAdminAuth();

return new KeyListIterator($this, $keys);
Expand All @@ -248,7 +276,8 @@ public function getIterator()
protected function internalGetItem(& $normalizedKey, & $success = null, & $casToken = null)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
$internalKey = $prefix . $normalizedKey;

$result = xcache_get($internalKey);
Expand All @@ -270,8 +299,9 @@ protected function internalGetItem(& $normalizedKey, & $success = null, & $casTo
*/
protected function internalHasItem(& $normalizedKey)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator();
$options = $this->getOptions();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
return xcache_isset($prefix . $normalizedKey);
}

Expand All @@ -285,7 +315,8 @@ protected function internalHasItem(& $normalizedKey)
protected function internalGetMetadata(& $normalizedKey)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
$internalKey = $prefix . $normalizedKey;

if (xcache_isset($internalKey)) {
Expand Down Expand Up @@ -320,7 +351,8 @@ protected function internalGetMetadata(& $normalizedKey)
protected function internalSetItem(& $normalizedKey, & $value)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator();
$namespace = $options->getNamespace();
$prefix = ($options === '') ? '' : $namespace . $options->getNamespaceSeparator();
$internalKey = $prefix . $normalizedKey;
$ttl = $options->getTtl();

Expand All @@ -344,7 +376,8 @@ protected function internalSetItem(& $normalizedKey, & $value)
protected function internalRemoveItem(& $normalizedKey)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
$internalKey = $prefix . $normalizedKey;

return xcache_unset($internalKey);
Expand All @@ -361,7 +394,8 @@ protected function internalRemoveItem(& $normalizedKey)
protected function internalIncrementItem(& $normalizedKey, & $value)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
$internalKey = $prefix . $normalizedKey;
$ttl = $options->getTtl();
$value = (int) $value;
Expand All @@ -380,7 +414,8 @@ protected function internalIncrementItem(& $normalizedKey, & $value)
protected function internalDecrementItem(& $normalizedKey, & $value)
{
$options = $this->getOptions();
$prefix = $options->getNamespace() . $options->getNamespaceSeparator();
$namespace = $options->getNamespace();
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator();
$internalKey = $prefix . $normalizedKey;
$ttl = $options->getTtl();
$value = (int) $value;
Expand Down