-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Add command to delete an item from a cache pool #26223
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
Conversation
06148c8
to
26a049e
Compare
$io = new SymfonyStyle($input, $output); | ||
$pool = $input->getArgument('pool'); | ||
$key = $input->getArgument('key'); | ||
$cachePool = $this->getApplication()->getKernel()->getContainer()->get($pool); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means the pool has to be public.
What about going through the Psr6CacheClearer instead?
26a049e
to
56dd080
Compare
} | ||
|
||
if (!$cachePool->deleteItem($key)) { | ||
return $io->error(sprintf('Cache item "%s" could not be deleted', $key)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The warning and error functions do not return a status code, however, I would imagine that at least the error should return a status code other than 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm aware that they don't return a status code, but for me this is just cleaner than
$io->warning(sprintf('Cache item "%s" does not exist in cache pool "%s"', $key, $pool));
return;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the error
I think it might be better to rather throw an exception, which should then have a proper error return code set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go for an exception then :)
* | ||
* @author Pierre du Plessis <pdples@gmail.com> | ||
*/ | ||
final class CachePoolDeleteCommand extends Command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this can only delete an item as specified in descriptions (key
is required), wouldn't CachePooltemDeleteCommand
be more accurate? Also, there's a tyop in the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches the name of the command, and is good enough IMHO as nothing else than an item can be deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches the name of the command
I was thinking about renaming both.
as nothing else than an item can be deleted.
Not everyone may know that though and can have different expectations. But as long as it's documented well, it's ok, I guess.
$cachePool = $this->poolClearer->getPool($pool); | ||
|
||
if (!$cachePool->hasItem($key)) { | ||
return $io->warning(sprintf('Cache item "%s" does not exist in cache pool "%s"', $key, $pool)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to turn this into a notice, and to explicitly return instead ($io->warning
doesn't return anything AFAIK)
} | ||
|
||
if (!$cachePool->deleteItem($key)) { | ||
return $io->error(sprintf('Cache item "%s" could not be deleted', $key)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go for an exception then :)
return $io->error(sprintf('Cache item "%s" could not be deleted', $key)); | ||
} | ||
|
||
$io->success(sprintf('Cache item "%s" was successfully deleted.', $key)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest to log only in verbose mode (same above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hum, maybe not actually :)
3451432
to
dccd939
Compare
* | ||
* @author Pierre du Plessis <pdples@gmail.com> | ||
*/ | ||
final class CachePooltemDeleteCommand extends Command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing I
before tem
, nice typo :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this doesn't match the name of the command
cache:pool:delete
LGTM, so the previous name was OK IMHO
dccd939
to
89355ba
Compare
$cachePool = $this->poolClearer->getPool($pool); | ||
|
||
if (!$cachePool->hasItem($key)) { | ||
$io->warning(sprintf('Cache item "%s" does not exist in cache pool "%s".', $key, $pool)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be a notice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, forgot about this. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with one minor comment
{ | ||
$this | ||
->setDefinition(array( | ||
new InputArgument('pool', InputArgument::REQUIRED, 'The cache pool to delete an item from'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache pool from which to delete an item
?
Thank you @pierredup. |
… cache pool (pierredup) This PR was squashed before being merged into the 4.1-dev branch (closes #26223). Discussion ---------- [FrameworkBundle] Add command to delete an item from a cache pool | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | N/A | License | MIT | Doc PR | TBD Currently there is no way to clear a specific item from a cache pool (except programatically), the entire pool needs to be cleared. Especially during development, when implementing caching, it is useful to delete a specific key to test functionality. Clearing the entire pool, means that everything will need to be cached again, adding unnecessary execution time. I propose adding a new command, `cache:pool:delete` to delete a specific item from a cache pool Commits ------- fd43e81 [FrameworkBundle] Add command to delete an item from a cache pool
|
||
private $poolClearer; | ||
|
||
public function __construct(Psr6CacheClearer $poolClearer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to inject the cache clearer to then use it to fetch a pool? Shouldn't we rather inject the pools directly?
Currently there is no way to clear a specific item from a cache pool (except programatically), the entire pool needs to be cleared.
Especially during development, when implementing caching, it is useful to delete a specific key to test functionality. Clearing the entire pool, means that everything will need to be cached again, adding unnecessary execution time.
I propose adding a new command,
cache:pool:delete
to delete a specific item from a cache pool