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

Commit

Permalink
Merge branch 'cache_eventFix'
Browse files Browse the repository at this point in the history
  • Loading branch information
akrabat committed Apr 23, 2012
Show file tree
Hide file tree
Showing 4 changed files with 278 additions and 33 deletions.
65 changes: 34 additions & 31 deletions src/Storage/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public function getItem($key, array $options = array())
return $eventRs->last();
}

$result = $this->internalGetItem($key, $options);
$result = $this->internalGetItem($args['key'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -474,7 +474,7 @@ public function getItems(array $keys, array $options = array())
return $eventRs->last();
}

$result = $this->internalGetItems($keys, $options);
$result = $this->internalGetItems($args['keys'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -549,7 +549,7 @@ public function hasItem($key, array $options = array())
return $eventRs->last();
}

$result = $this->internalHasItem($key, $options);
$result = $this->internalHasItem($args['key'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -617,7 +617,7 @@ public function hasItems(array $keys, array $options = array())
return $eventRs->last();
}

$result = $this->internalHasItems($keys, $options);
$result = $this->internalHasItems($args['keys'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -686,7 +686,7 @@ public function getMetadata($key, array $options = array())
return $eventRs->last();
}

$result = $this->internalGetMetadata($key, $options);
$result = $this->internalGetMetadata($args['key'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -759,7 +759,7 @@ public function getMetadatas(array $keys, array $options = array())
return $eventRs->last();
}

$result = $this->internalGetMetadatas($keys, $options);
$result = $this->internalGetMetadatas($args['keys'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -844,7 +844,7 @@ public function setItem($key, $value, array $options = array())
return $eventRs->last();
}

$result = $this->internalSetItem($key, $value, $options);
$result = $this->internalSetItem($args['key'], $args['value'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -909,7 +909,7 @@ public function setItems(array $keyValuePairs, array $options = array())
return $eventRs->last();
}

$result = $this->internalSetItems($keyValuePairs, $options);
$result = $this->internalSetItems($args['keyValuePairs'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -982,7 +982,7 @@ public function addItem($key, $value, array $options = array())
return $eventRs->last();
}

$result = $this->internalAddItem($key, $value, $options);
$result = $this->internalAddItem($args['key'], $args['value'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1053,7 +1053,7 @@ public function addItems(array $keyValuePairs, array $options = array())
return $eventRs->last();
}

$result = $this->internalAddItems($keyValuePairs, $options);
$result = $this->internalAddItems($args['keyValuePairs'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1126,7 +1126,7 @@ public function replaceItem($key, $value, array $options = array())
return $eventRs->last();
}

$result = $this->internalReplaceItem($key, $value, $options);
$result = $this->internalReplaceItem($args['key'], $args['value'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1198,7 +1198,7 @@ public function replaceItems(array $keyValuePairs, array $options = array())
return $eventRs->last();
}

$result = $this->internalReplaceItems($keyValuePairs, $options);
$result = $this->internalReplaceItems($args['keyValuePairs'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1263,6 +1263,7 @@ public function checkAndSetItem($token, $key, $value, array $options = array())
$this->normalizeOptions($options);
$this->normalizeKey($key);
$args = new ArrayObject(array(
'token' => & $token,
'key' => & $key,
'value' => & $value,
'options' => & $options,
Expand All @@ -1274,7 +1275,7 @@ public function checkAndSetItem($token, $key, $value, array $options = array())
return $eventRs->last();
}

$result = $this->internalCheckAndSetItem($token, $key, $value, $options);
$result = $this->internalCheckAndSetItem($args['token'], $args['key'], $args['value'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1348,7 +1349,7 @@ public function touchItem($key, array $options = array())
return $eventRs->last();
}

$result = $this->internalTouchItem($key, $options);
$result = $this->internalTouchItem($args['key'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1429,7 +1430,7 @@ public function touchItems(array $keys, array $options = array())
return $eventRs->last();
}

$result = $this->internalTouchItems($keys, $options);
$result = $this->internalTouchItems($args['keys'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1496,7 +1497,7 @@ public function removeItem($key, array $options = array())
return $eventRs->last();
}

$result = $this->internalRemoveItem($key, $options);
$result = $this->internalRemoveItem($args['key'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1556,7 +1557,7 @@ public function removeItems(array $keys, array $options = array())
return $eventRs->last();
}

$result = $this->internalRemoveItems($keys, $options);
$result = $this->internalRemoveItems($args['keys'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1639,7 +1640,7 @@ public function incrementItem($key, $value, array $options = array())
return $eventRs->last();
}

$result = $this->internalIncrementItem($key, $value, $options);
$result = $this->internalIncrementItem($args['key'], $args['value'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1711,7 +1712,7 @@ public function incrementItems(array $keyValuePairs, array $options = array())
return $eventRs->last();
}

$result = $this->internatIncrementItems($keyValuePairs, $options);
$result = $this->internalIncrementItems($args['keyValuePairs'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand All @@ -1734,11 +1735,11 @@ public function incrementItems(array $keyValuePairs, array $options = array())
* @return boolean
* @throws Exception
*/
protected function internatIncrementItems(array & $normalizedKeyValuePairs, array & $normalizedOptions)
protected function internalIncrementItems(array & $normalizedKeyValuePairs, array & $normalizedOptions)
{
$ret = true;
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
$ret = ($this->incrementItem($normalizedKey, $value, $normalizedOptions) !== false) && $ret;
$ret = ($this->internalIncrementItem($normalizedKey, $value, $normalizedOptions) !== false) && $ret;
}
return $ret;
}
Expand Down Expand Up @@ -1784,7 +1785,7 @@ public function decrementItem($key, $value, array $options = array())
return $eventRs->last();
}

$result = $this->internalDecrementItem($key, $value, $options);
$result = $this->internalDecrementItem($args['key'], $args['value'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -1856,7 +1857,7 @@ public function decrementItems(array $keyValuePairs, array $options = array())
return $eventRs->last();
}

$result = $this->internatDecrementItems($keyValuePairs, $options);
$result = $this->internalDecrementItems($args['keyValuePairs'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand All @@ -1879,7 +1880,7 @@ public function decrementItems(array $keyValuePairs, array $options = array())
* @return boolean
* @throws Exception
*/
protected function internatDecrementItems(array & $normalizedKeyValuePairs, array & $normalizedOptions)
protected function internalDecrementItems(array & $normalizedKeyValuePairs, array & $normalizedOptions)
{
$ret = true;
foreach ($normalizedKeyValuePairs as $normalizedKey => $value) {
Expand Down Expand Up @@ -1939,7 +1940,7 @@ public function getDelayed(array $keys, array $options = array())
return $eventRs->last();
}

$result = $this->internalGetDelayed($keys, $options);
$result = $this->internalGetDelayed($args['keys'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -2036,7 +2037,7 @@ public function find($mode = self::MATCH_ACTIVE, array $options = array())
return $eventRs->last();
}

$result = $this->internalFind($mode, $options);
$result = $this->internalFind($args['mode'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -2241,7 +2242,7 @@ public function clear($mode = self::MATCH_EXPIRED, array $options = array())
return $eventRs->last();
}

$result = $this->internalClear($mode, $options);
$result = $this->internalClear($args['mode'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -2310,7 +2311,7 @@ public function clearByNamespace($mode = self::MATCH_EXPIRED, array $options = a
return $eventRs->last();
}

$result = $this->internalClearByNamespace($mode, $options);
$result = $this->internalClearByNamespace($args['mode'], $args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -2362,15 +2363,17 @@ public function optimize(array $options = array())
return false;
}

$args = new ArrayObject();
$args = new ArrayObject(array(
'options' => & $options
));

try {
$eventRs = $this->triggerPre(__FUNCTION__, $args);
if ($eventRs->stopped()) {
return $eventRs->last();
}

$result = $this->internalOptimize();
$result = $this->internalOptimize($args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down Expand Up @@ -2458,7 +2461,7 @@ public function getCapacity(array $options = array())
return $eventRs->last();
}

$result = $this->internalGetCapacity($options);
$result = $this->internalGetCapacity($args['options']);
return $this->triggerPost(__FUNCTION__, $args, $result);
} catch (\Exception $e) {
return $this->triggerException(__FUNCTION__, $args, $e);
Expand Down
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static function getSystemMemoryCapacity()
// *nix
if (false === ($meminfo = @file_get_contents('/proc/meminfo'))) {
$lastErr = error_get_last();
throw new Exception\RuntimeException("Can't read '/proc/meminfo': {$lastErr['messagae']}");
throw new Exception\RuntimeException("Can't read '/proc/meminfo': {$lastErr['message']}");
} elseif (!preg_match_all('/(\w+):\s*(\d+\s*\w*)[\r|\n]/i', $meminfo, $matches, PREG_PATTERN_ORDER)) {
throw new Exception\RuntimeException("Can't parse '/proc/meminfo'");
}
Expand Down
Loading

0 comments on commit 42cb3fe

Please sign in to comment.