Skip to content

Update deps #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
"ext-sockets": "*",
"doctrine/collections": "^1.3",
"doctrine/dbal": "^3.0",
"psr/simple-cache": "^1.0",
"symfony/dependency-injection": "^3.1|^4.0|^5.0",
"symfony/event-dispatcher": "^3.1|^4.0|^5.0"
"psr/simple-cache": "^1.0 | ^3.0",
"symfony/event-dispatcher": "^3.1|^4.0|^5.0|^6.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0"
Expand Down
87 changes: 61 additions & 26 deletions src/MySQLReplication/Cache/ArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,68 @@

namespace MySQLReplication\Cache;

use MySQLReplication\Config\Config;
use Composer\InstalledVersions;
use Psr\SimpleCache\CacheInterface;

class ArrayCache implements CacheInterface
{
if (class_exists(InstalledVersions::class) && version_compare(InstalledVersions::getVersion("psr/simple-cache"), '3.0.0', ">=")) {
class ArrayCache implements CacheInterface
{
use ArrayCacheTrait;

/**
* @inheritDoc
*/
public function get(string $key, $default = null): mixed
{
return $this->has($key) ? $this->tableMapCache[$key] : $default;
}

/**
* @inheritDoc
*/
public function getMultiple(iterable $keys, $default = null): iterable
{
$data = [];
foreach ($keys as $key) {
if ($this->has($key)) {
$data[$key] = $this->tableMapCache[$key];
}
}

return [] !== $data ? $data : $default;
}
}
} else {
class ArrayCache implements CacheInterface
{
use ArrayCacheTrait;

/**
* @inheritDoc
*/
public function get($key, $default = null)
{
return $this->has($key) ? $this->tableMapCache[$key] : $default;
}

/**
* @inheritDoc
*/
public function getMultiple($keys, $default = null)
{
$data = [];
foreach ($keys as $key) {
if ($this->has($key)) {
$data[$key] = $this->tableMapCache[$key];
}
}

return [] !== $data ? $data : $default;
}
}
}

trait ArrayCacheTrait {
private $tableMapCache = [];

/**
Expand All @@ -20,13 +77,6 @@ public function __construct(int $tableCacheSize = 128)
$this->tableCacheSize = $tableCacheSize;
}

/**
* @inheritDoc
*/
public function get($key, $default = null)
{
return $this->has($key) ? $this->tableMapCache[$key] : $default;
}

/**
* @inheritDoc
Expand All @@ -46,21 +96,6 @@ public function clear(): bool
return true;
}

/**
* @inheritDoc
*/
public function getMultiple($keys, $default = null)
{
$data = [];
foreach ($keys as $key) {
if ($this->has($key)) {
$data[$key] = $this->tableMapCache[$key];
}
}

return [] !== $data ? $data : $default;
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -114,4 +149,4 @@ public function delete($key): bool

return true;
}
}
}