mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
fix memcache regex search
This commit is contained in:
parent
a8ebed1d3b
commit
06c7f308e2
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user