-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add HRecycle() to manually recycle expired hashKey
- Loading branch information
Showing
5 changed files
with
125 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Workbunny\WebmanSharedCache\Commands; | ||
|
||
use Symfony\Component\Console\Helper\QuestionHelper; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\ConfirmationQuestion; | ||
|
||
class WorkbunnyWebmanSharedCacheEnable extends AbstractCommand | ||
{ | ||
protected static string $defaultName = 'workbunny:shared-cache-enable'; | ||
protected static string $defaultDescription = 'Enable APCu cache with specified settings. '; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure(): void | ||
{ | ||
$this | ||
->setDescription('Enable APCu cache with specified settings.') | ||
->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'Specify configuration name', 'apcu-cache.ini') | ||
->addOption('target', 't', InputOption::VALUE_REQUIRED, 'Specify target location', '/usr/local/etc/php/conf.d') | ||
->addOption('size', 'si', InputOption::VALUE_REQUIRED, 'Configure apcu.shm_size', '1024M') | ||
->addOption('segments', 'se', InputOption::VALUE_REQUIRED, 'Configure apcu.shm_segments', 1) | ||
->addOption('mmap', 'm', InputOption::VALUE_REQUIRED, 'Configure apcu.mmap_file_mask', '') | ||
->addOption('gc_ttl', 'gc', InputOption::VALUE_REQUIRED, 'Configure apcu.gc_ttl', 3600); | ||
} | ||
|
||
/** | ||
* @param InputInterface $input | ||
* @param OutputInterface $output | ||
* @return int | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$fileName = $input->getOption('file'); | ||
$target = $input->getOption('target'); | ||
$shmSize = $input->getOption('size'); | ||
$shmSegments = $input->getOption('segments'); | ||
$mmapFileMask = $input->getOption('mmap'); | ||
$gcTtl = $input->getOption('gc_ttl'); | ||
|
||
if (!is_dir($target)) { | ||
return $this->error($output, "Target directory does not exist: $target. "); | ||
} | ||
$configContent = <<<EOF | ||
apc.enabled=1 | ||
apc.enable_cli=1 | ||
apc.shm_segments=$shmSegments | ||
apc.shm_size=$shmSize | ||
apc.mmap_file_mask=$mmapFileMask | ||
apc.gc_ttl=$gcTtl | ||
EOF; | ||
$filePath = "$target/$fileName"; | ||
|
||
if (file_exists($filePath)) { | ||
/** @var QuestionHelper $helper */ | ||
$helper = $this->getHelper('question'); | ||
$question = new ConfirmationQuestion("Configuration file already exists at $filePath. Overwrite? (y/N) ", false); | ||
|
||
if (!$helper->ask($input, $output, $question)) { | ||
return $this->success($output, "Operation aborted. "); | ||
} | ||
} | ||
|
||
file_put_contents($filePath, $configContent); | ||
return $this->success($output, "Configuration file created at: $filePath. "); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/config/plugin/workbunny/webman-shared-cache/command.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
/** | ||
* This file is part of workbunny. | ||
* | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @author chaz6chez<[email protected]> | ||
* @copyright chaz6chez<[email protected]> | ||
* @link https://github.com/workbunny/webman-push-server | ||
* @license https://github.com/workbunny/webman-push-server/blob/main/LICENSE | ||
*/ | ||
declare(strict_types=1); | ||
|
||
return [ | ||
Workbunny\WebmanSharedCache\Commands\WorkbunnyWebmanSharedCacheEnable::class, | ||
Workbunny\WebmanSharedCache\Commands\WorkbunnyWebmanSharedCacheClean::class, | ||
]; |