-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Add (pdo|chain) cache (adapter|simple) prune method #23603
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
[Cache] Add (pdo|chain) cache (adapter|simple) prune method #23603
Conversation
109d18f
to
f332e68
Compare
@nicolas-grekas Is passing |
I think it is yes |
fb85ed6
to
2e328b0
Compare
Aside from the tests, which take up the bulk of the additions, this amends |
Test failures seem unrelated, FYI. |
5d68adb
to
7385048
Compare
rebase unlocked |
7385048
to
78d31e1
Compare
Wonderful; thanks. Rebased. |
* | ||
* @return bool | ||
*/ | ||
private function doPrune(array $caches) |
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 think this doesn't deserve a trait :)
public function prune() | ||
{ | ||
$pdoConn = $this->getConnection(); | ||
$selects = $pdoConn->prepare("SELECT $this->idCol FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time"); |
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 implementation is no-go, it doesn't scale at all. Can't we just do one single DELETE instead?
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.
Of course, you are right; I'd pulled the from another method, but that one had a need to also return values. :-) Only three lines now.
17fce58
to
87ac9a6
Compare
@@ -96,6 +98,18 @@ public function testPrune() | |||
$cache->save($item); | |||
}; | |||
|
|||
$doSet('foo', 'foo-val', new \DateInterval('PT05S')); |
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 may seem to duplicate tests, but the prior tests didn't check pruning of more than one item at a time; so this test ensures four items can be all pruned at once.
Update pushed that addresses your review comments. |
@@ -140,6 +140,17 @@ public function createTable() | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function prune() | |||
{ | |||
$deletes = $this->getConnection()->prepare("DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time"); |
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.
What about adding a LIKE clause for the namespace?
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 the namespace
property is a private
property of AbstractAdapter
(well, actually the trait AbstractTrait
but that is used by AbstractAdapter
) how am I to determine the namespace? I think it's a fine idea, just not sure how to accomplish it.
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.
we have the namespace in the init method, we can borrow it from there
Pushed a commit that re-declares |
11bc2ad
to
5d0e016
Compare
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.
looks good.
just one thing:
PHP Strict Standards: Static function Symfony\Component\Cache\Tests\Traits\PdoPruneableTrait::fail() should not be abstract in /home/travis/build/symfony/symfony/src/Symfony/Component/Cache/Tests/Traits/PdoPruneableTrait.php on line 44
{ | ||
$deleteSql = "DELETE FROM $this->table WHERE $this->lifetimeCol + $this->timeCol <= :time"; | ||
|
||
if ($this->namespace) { |
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->namespace
$delete = $this->getConnection()->prepare($deleteSql); | ||
$delete->bindValue(':time', time(), \PDO::PARAM_INT); | ||
|
||
if ($this->namespace) { |
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.
same
5d0e016
to
d89caf3
Compare
@nicolas-grekas Comments addressed and changes pushed. I've squashed everything, as well. I'm sure you noticed I didn't add
If you decide it does add value, though, let me know and I'll be happy to include it here. Otherwise, thanks for the quick reviews again! |
Pushed two very small changes in latest commit:
Trivial stuff, but just mentioning so as not to slip in changes without people knowing. |
@robfrawley the title of this PR still says "WIP", what's the real status? (btw, I personally prefer not putting statuses in PR title, we have labels for that :) ) |
@nicolas-grekas Sorry about the delay, but now I've updated the title to remove the "WIP" --- as far as I'm concerned this is ready for merge. (Note taken about the use of titles versus labels ;) ). |
Are there any additional changed you need me to implement? Also, when you have a moment, can you review the documentation PR (symfony/symfony-docs#8209) and advise if it adequately describes the changes from this PR as well as #23451. |
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 minor comment
|
||
$getPdoConn = $o->getMethod('getConnection'); | ||
$getPdoConn->setAccessible(true); | ||
$refPropVal = function ($name) use ($cache, $o) { |
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.
tests can know the default value so I would hard code them instead to reduce the boilerplate and logic in test cases
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.
Done.
c3ef400
to
b20a237
Compare
Test failure unrelated. |
Thank you @robfrawley. |
…ethod (robfrawley) This PR was merged into the 3.4 branch. Discussion ---------- [Cache] Add (pdo|chain) cache (adapter|simple) prune method | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | symfony/symfony-docs#8209 This is additional work toward making more cache implementations use the `PruneableInterface` contract. Specifically, this pull request focuses on `(Pdo|Chain)(Cache|Adapter)`, as suggested by @nicolas-grekas in #23451 (comment). Commits ------- b20a237 add (pdo|chain) cache (adapter|simple) prune method
…dapter|simple) prune method and prune command (robfrawley, javiereguiluz) This PR was merged into the 3.4 branch. Discussion ---------- [Cache] Document (filesystem|phpfiles|pdo|chain) cache (adapter|simple) prune method and prune command This PR documents the changes introduced in symfony/symfony#23451 and symfony/symfony#23603: - The addition of [`PruneableInterface`](https://github.com/symfony/cache/blob/master/PruneableInterface.php) - The variouse, concrete [`PruneableInterface::prune()`](https://github.com/symfony/cache/blob/master/PruneableInterface.php#L22) implementations in [`ChainAdapter`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Adapter/ChainAdapter.php), [`FilesystemAdapter`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Adapter/FilesystemAdapter.php), [`PdoAdapter`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Adapter/PdoAdapter.php), [`PhpFilesAdapter`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php),[ `ChainCache`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Simple/ChainCache.php), [`FilesystemCache`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Simple/FilesystemCache.php), [`PdoCache`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Simple/PdoCache.php), [`PhpFilesCache`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Simple/PhpFilesCache.php), and [`TagAwareAdapter`](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php). - The addition of [`CachePoolPruneCommand`](https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Command/CachePoolPruneCommand.php), invokable via `cache:pool:prune`. This command iterates over all services tagged `cache.pool` and calls the [`PruneableInterface::prune()`](https://github.com/symfony/cache/blob/master/PruneableInterface.php#L22) method on those that implement [`PruneableInterface`](https://github.com/symfony/cache/blob/master/PruneableInterface.php) Additionally, some language changes and cleanup has been implemented for the various cache docs. Of note are the following changes: - Additional `note` blocks for all caches that implement [`PruneableInterface`](https://github.com/symfony/cache/blob/master/PruneableInterface.php) - Addition of `prune()` description and usage example on the chain adapter - Addition of a `tip` about achieving better performance with the filesystem adapter by utilizing `tmpfs` or another ram disk solution - Fix for an incorrect `use` statement in the PHP array cache adapter code example - Addition of documentation page for PHP files adapter - Addition of a "pruning cache items" explanation and example on the main cache pools page Commits ------- 54a1e62 Typo 1322ffd Typos and wrapped long lines 5bea1e6 Fixed a typo eb70a36 Wrapped long lines ea29252 document cache pruning functionality - note the addition of PruneableInterface - note the variouse, concrete PruneableInterface::prune() implementations in ChainAdapter, FilesystemAdapter, PdoAdapter, PhpFilesAdapter, ChainCache, FilesystemCache, PdoCache, PhpFilesCache, and TagAwareAdapter. - note the addition of CachePoolPruneCommand, invokable via cache:pool:prune. This command iterates over all services tagged cache.pool and calls the PruneableInterface::prune() method on those that implement PruneableInterface - rewording of some adapter text for clarity - additional note blocks for all caches that implement PruneableInterface - addition of prune() description and usage example on the chain adapter - addition of a tip about achieving better performance with the filesystem adapter by utilizing tmpfs or another ram disk solution - fix for an incorrect use statement in the PHP array cache adapter code example - addition of documentation page for PHP files adapter - addition of a "pruning cache items" explanation and example on the main cache pools page
This is additional work toward making more cache implementations use the
PruneableInterface
contract (an extension of #23451). Specifically, this pull request focuses on(Pdo|Chain)(Cache|Adapter)
, as suggested by @nicolas-grekas in #23451 (comment).