Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Closed
pierredup wants to merge4 commits intosymfony:masterfrompierredup:cache-commands

Conversation

@pierredup
Copy link
Contributor

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsN/A
LicenseMIT
Doc PRTBD

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

pierrefeelunique reacted with thumbs up emoji
$io = new SymfonyStyle($input, $output);
$pool = $input->getArgument('pool');
$key = $input->getArgument('key');
$cachePool = $this->getApplication()->getKernel()->getContainer()->get($pool);

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));
Copy link
Contributor

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.

Copy link
ContributorAuthor

@pierreduppierredupFeb 20, 2018
edited
Loading

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;

Copy link
ContributorAuthor

@pierreduppierredupFeb 20, 2018
edited
Loading

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

linaori reacted with thumbs up emoji

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
Copy link

@Destroy666xDestroy666xFeb 20, 2018
edited
Loading

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.

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.

Copy link

@Destroy666xDestroy666xFeb 22, 2018
edited
Loading

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));
Copy link
Member

@nicolas-grekasnicolas-grekasFeb 21, 2018
edited
Loading

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));

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));

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

hum, maybe not actually :)

*
* @author Pierre du Plessis <pdples@gmail.com>
*/
final class CachePooltemDeleteCommand extends Command

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

missingI beforetem, nice typo :)

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

$cachePool = $this->poolClearer->getPool($pool);

if (!$cachePool->hasItem($key)) {
$io->warning(sprintf('Cache item "%s" does not exist in cache pool "%s".', $key, $pool));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should be a notice

Copy link
ContributorAuthor

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

Copy link
Member

@nicolas-grekasnicolas-grekas left a 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'),
Copy link
Member

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
Copy link
Member

Thank you@pierredup.

nicolas-grekas added a commit that referenced this pull requestMar 2, 2018
… 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)
Copy link
Member

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?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@xabbuhxabbuhxabbuh left review comments

@chalasrchalasrchalasr approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

+2 more reviewers

@linaorilinaorilinaori left review comments

@Destroy666xDestroy666xDestroy666x left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

7 participants

@pierredup@nicolas-grekas@linaori@xabbuh@Destroy666x@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp