From 06c7f308e2ff7b854f989ffd98a2ff7a99549089 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 13 Oct 2021 18:18:53 +0200 Subject: [PATCH] fix memcache regex search --- .../Cache/Connection/ConnectionInterface.php | 24 --------- DataStorage/Cache/Connection/MemCached.php | 49 ------------------- .../Cache/Connection/MemCachedTest.php | 38 -------------- 3 files changed, 111 deletions(-) diff --git a/DataStorage/Cache/Connection/ConnectionInterface.php b/DataStorage/Cache/Connection/ConnectionInterface.php index f91ad297a..87173b14f 100644 --- a/DataStorage/Cache/Connection/ConnectionInterface.php +++ b/DataStorage/Cache/Connection/ConnectionInterface.php @@ -101,18 +101,6 @@ interface ConnectionInterface extends DataStorageConnectionInterface */ public function get(int | string $key, int $expire = -1) : mixed; - /** - * Get cache by pattern. - * - * @param string $key Unique cache key - * @param int $expire Valid duration (in s). In case the data needs to be newer than the defined expiration time. If the expiration date is larger than the defined expiration time and supposed to be expired it will not remove the outdated cache. - * - * @return array Cache values - * - * @since 1.0.0 - */ - public function getLike(string $pattern, int $expire = -1) : array; - /** * Exists cache by key. * @@ -137,18 +125,6 @@ interface ConnectionInterface extends DataStorageConnectionInterface */ public function delete(int | string $key, int $expire = -1) : bool; - /** - * Remove value by pattern. - * - * @param string $key Unique cache key - * @param int $expire Valid duration (in s) - * - * @return bool - * - * @since 1.0.0 - */ - public function deleteLike(string $pattern, int $expire = -1) : bool; - /** * Removing all cache elements larger or equal to the expiration date. Call flushAll for removing persistent cache elements (expiration is negative) as well. * diff --git a/DataStorage/Cache/Connection/MemCached.php b/DataStorage/Cache/Connection/MemCached.php index ff7d543c0..7612801f2 100644 --- a/DataStorage/Cache/Connection/MemCached.php +++ b/DataStorage/Cache/Connection/MemCached.php @@ -195,36 +195,6 @@ final class MemCached extends ConnectionAbstract $this->delete((string) $old); } - /** - * {@inheritdoc} - */ - public function getLike(string $pattern, int $expire = -1) : array - { - if ($this->status !== CacheStatus::OK) { - return []; - } - - $keys = $this->con->getAllKeys(); - $values = []; - - var_dump($keys); - - foreach ($keys as $key) { - if (\preg_match('/' . $pattern . '/', $key) === 1) { - $result = $this->con->get($key); - if (\is_string($result)) { - $type = (int) $result[0]; - $start = (int) \strpos($result, self::DELIM); - $result = $this->reverseValue($type, $result, $start); - } - - $values[] = $result; - } - } - - return $values; - } - /** * Parse cached value * @@ -280,25 +250,6 @@ final class MemCached extends ConnectionAbstract } } - /** - * {@inheritdoc} - */ - public function deleteLike(string $pattern, int $expire = -1) : bool - { - if ($this->status !== CacheStatus::OK) { - return false; - } - - $keys = $this->con->getAllKeys(); - foreach ($keys as $key) { - if (\preg_match('/' . $pattern . '/', $key) === 1) { - $this->con->delete($key); - } - } - - return true; - } - /** * {@inheritdoc} */ diff --git a/tests/DataStorage/Cache/Connection/MemCachedTest.php b/tests/DataStorage/Cache/Connection/MemCachedTest.php index 86ec16f3c..5711b930a 100644 --- a/tests/DataStorage/Cache/Connection/MemCachedTest.php +++ b/tests/DataStorage/Cache/Connection/MemCachedTest.php @@ -150,30 +150,6 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase self::assertFalse($this->cache->exists('invalid')); } - public function testGetLike() : void - { - $this->cache->set('key1', 'testVal1'); - $this->cache->set('key2', 'testVal2'); - self::assertEquals(['testVal1', 'testVal2'], $this->cache->getLike('key\d')); - } - - public function testExpiredGetLike() : void - { - $this->cache->set('key1', 'testVal1', 2); - $this->cache->set('key2', 'testVal2', 2); - \sleep(1); - self::assertEquals([], \array_diff(['testVal1', 'testVal2'], $this->cache->getLike('key\d'))); - self::assertEquals([], $this->cache->getLike('key\d', 0)); - \sleep(3); - self::assertEquals([], $this->cache->getLike('key\d')); - } - - public function testGetLikeInvalidStatus() : void - { - TestUtils::setMember($this->cache, 'status', CacheStatus::FAILURE); - self::assertEquals([], $this->cache->getLike('key\d')); - } - public function testIncrement() : void { $this->cache->set(1, 1); @@ -205,20 +181,6 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase self::assertEquals('testVal1', $this->cache->get('b')); } - public function testDeleteLike() : void - { - $this->cache->set('key1', 'testVal1'); - $this->cache->set('key2', 'testVal2'); - self::assertTrue($this->cache->deleteLike('key\d')); - self::assertEquals([], $this->cache->getLike('key\d')); - } - - public function testDeleteLikeInvalidStatus() : void - { - TestUtils::setMember($this->cache, 'status', CacheStatus::FAILURE); - self::assertFalse($this->cache->deleteLike('key\d')); - } - public function testUpdateExpire() : void { $this->cache->set('key2', 'testVal2', 1);