summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
3f0f3b6)
- filterPrefix => filterArrayKeysByPrefix()
- Logging failed Executions of getAllKeys and get from Memcached
- * Filters a list for a given prefix
+ * Filters the keys of an array with a given prefix
+ * Returns the filtered keys as an new array
- * @param array $list the list
- * @param string|null $prefix the prefix
+ * @param array $array The array, which should get filtered
+ * @param string|null $prefix The prefix (if null, all keys will get returned)
- * @return array the filtered list
+ * @return array The filtered array with just the keys
- protected function filterPrefix($list, $prefix = null)
+ protected function filterArrayKeysByPrefix($array, $prefix = null)
- return array_keys($list);
+ return array_keys($array);
- foreach (array_keys($list) as $key) {
+ foreach (array_keys($array) as $key) {
if (strpos($key, $prefix) === 0) {
array_push($result, $key);
}
if (strpos($key, $prefix) === 0) {
array_push($result, $key);
}
*/
public function getAllKeys($prefix = null)
{
*/
public function getAllKeys($prefix = null)
{
- return $this->filterPrefix($this->cachedData, $prefix);
+ return $this->filterArrayKeysByPrefix($this->cachedData, $prefix);
*/
public function getAllKeys($prefix = null)
{
*/
public function getAllKeys($prefix = null)
{
$allSlabs = $this->memcache->getExtendedStats('slabs');
foreach ($allSlabs as $slabs) {
foreach (array_keys($slabs) as $slabId) {
$cachedump = $this->memcache->getExtendedStats('cachedump', (int)$slabId);
$allSlabs = $this->memcache->getExtendedStats('slabs');
foreach ($allSlabs as $slabs) {
foreach (array_keys($slabs) as $slabId) {
$cachedump = $this->memcache->getExtendedStats('cachedump', (int)$slabId);
- foreach ($cachedump as $keys => $arrVal) {
+ foreach ($cachedump as $key => $arrVal) {
if (!is_array($arrVal)) {
continue;
}
if (!is_array($arrVal)) {
continue;
}
- $list = array_merge($list, array_keys($arrVal));
+ $keys = array_merge($keys, array_keys($arrVal));
- $list = $this->getOriginalKeys($list);
+ $keys = $this->getOriginalKeys($keys);
- return $this->filterPrefix($list, $prefix);
+ return $this->filterArrayKeysByPrefix($keys, $prefix);
*/
public function getAllKeys($prefix = null)
{
*/
public function getAllKeys($prefix = null)
{
- // Doesn't work because of https://github.com/php-memcached-dev/php-memcached/issues/367
- // returns everytime an empty array
- throw new InternalServerErrorException('getAllKeys for Memcached not supported yet');
+ $keys = $this->getOriginalKeys($this->memcached->getAllKeys());
- $list = $this->getOriginalKeys($this->memcached->getAllKeys());
-
- return $this->filterPrefix($list, $prefix);
+ if ($this->memcached->getResultCode() == Memcached::RES_SUCCESS) {
+ return $this->filterArrayKeysByPrefix($keys, $prefix);
+ } else {
+ logger('Memcached \'getAllKeys\' failed with ' . $this->memcached->getResultMessage(), LOGGER_ALL);
+ return [];
+ }
*/
public function get($key)
{
*/
public function get($key)
{
$cachekey = $this->getCacheKey($key);
// We fetch with the hostname as key to avoid problems with other applications
$value = $this->memcached->get($cachekey);
if ($this->memcached->getResultCode() === Memcached::RES_SUCCESS) {
$cachekey = $this->getCacheKey($key);
// We fetch with the hostname as key to avoid problems with other applications
$value = $this->memcached->get($cachekey);
if ($this->memcached->getResultCode() === Memcached::RES_SUCCESS) {
+ return $value;
+ } else {
+ logger('Memcached \'get\' failed with ' . $this->memcached->getResultMessage(), LOGGER_ALL);
+ return [];
$count = 0;
foreach ($keys as $key) {
$count = 0;
foreach ($keys as $key) {
- if (empty($prefix) || strpos($key, $prefix) === 0) {
- $this->out($key);
- $count++;
- }
}
$this->out($count . ' keys found');
}
$this->out($count . ' keys found');