Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| $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?
| } | ||
| 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 thatat least the error should return a status code other than 0.
pierredupFeb 20, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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;
pierredupFeb 20, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 theerror 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 |
Destroy666xFeb 20, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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'tCachePooltemDeleteCommand 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.
Destroy666xFeb 22, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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)); |
nicolas-grekasFeb 21, 2018 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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 todccd939Compare| * | ||
| * @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.
missingI beforetem, 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 commandcache:pool:delete LGTM, so the previous name was OK IMHO
| $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
nicolas-grekas left a comment
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?
nicolas-grekas commentedMar 2, 2018
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 | TBDCurrently 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 poolCommits-------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:deleteto delete a specific item from a cache pool