Skip to content

MCLOUD-6958: Command cache:evict does not support L2 cache configuration #44

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 3 commits into from
Sep 23, 2020
Merged
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
51 changes: 43 additions & 8 deletions Model/Cache/Evictor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class Evictor
const DEFAULT_SLEEP_TIMEOUT = 20000;
const CONFIG_PATH_ENABLED = 'cache_evict/enabled';
const CONFIG_PATH_LIMIT = 'cache_evict/limit';
const BACKEND_OPTION_KEY_SERVER = 'server';
const BACKEND_OPTION_KEY_PORT = 'port';
const BACKEND_OPTION_KEY_DATABASE = 'database';

/**
* @var DeploymentConfig
Expand Down Expand Up @@ -60,11 +63,8 @@ public function evict(): int
$name
));

if (!isset(
$cacheConfig['backend_options']['server'],
$cacheConfig['backend_options']['port'],
$cacheConfig['backend_options']['database']
)) {
$backendOptions = $this->getConfigBackendOptions((array)$cacheConfig);
if (!$this->validateBackendOptions($backendOptions)) {
$this->logger->debug(sprintf(
'Cache config for database "%s" config is not valid',
$name
Expand All @@ -74,9 +74,9 @@ public function evict(): int
}

$dbKeys = $this->run(
(string)$cacheConfig['backend_options']['server'],
(int)$cacheConfig['backend_options']['port'],
(int)$cacheConfig['backend_options']['database']
(string)$backendOptions[self::BACKEND_OPTION_KEY_SERVER],
(int)$backendOptions[self::BACKEND_OPTION_KEY_PORT],
(int)$backendOptions[self::BACKEND_OPTION_KEY_DATABASE]
);
$evictedKeys += $dbKeys;

Expand All @@ -86,6 +86,41 @@ public function evict(): int
return $evictedKeys;
}

/**
* Get Cache Config Value
*
* @param array $cacheConfig
* @return array
*/
private function getConfigBackendOptions(array $cacheConfig): array
{
$backendOptions = [];
if (isset($cacheConfig['backend_options'])) {
$backendOptions = $cacheConfig['backend_options'];
}
if (isset($cacheConfig['backend_options']['remote_backend_options'])) {
$backendOptions = $cacheConfig['backend_options']['remote_backend_options'];
}
return (array)$backendOptions;
}

/**
* Validate Cache Configuration
*
* @param array $backendOptions
* @return bool
*/
private function validateBackendOptions(array $backendOptions): bool
{
if (isset($backendOptions[self::BACKEND_OPTION_KEY_SERVER])
&& isset($backendOptions[self::BACKEND_OPTION_KEY_PORT])
&& isset($backendOptions[self::BACKEND_OPTION_KEY_DATABASE])
) {
return true;
}
return false;
}

/**
* @param string $host
* @param int $port
Expand Down