8000 [Cache] Commit items implicitly only when deferred keys are requested by sbelyshkin · Pull Request #43302 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Cache] Commit items implicitly only when deferred keys are requested #43302

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

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ public function invalidateTags(array $tags)
*/
public function hasItem($key)
{
if ($this->deferred) {
if (\is_string($key) && isset($this->deferred[$key])) {
$this->commit();
}

if (!$this->pool->hasItem($key)) {
return false;
}
Expand Down Expand Up @@ -201,18 +202,21 @@ public function getItem($key)
*/
public function getItems(array $keys = [])
{
if ($this->deferred) {
$this->commit();
}
$tagKeys = [];
$commit = false;

foreach ($keys as $key) {
if ('' !== $key && \is_string($key)) {
$commit = $commit || isset($this->deferred[$key]);
$key = static::TAGS_PREFIX.$key;
$tagKeys[$key] = $key;
}
}

if ($commit) {
$this->commit();
}

try {
$items = $this->pool->getItems($tagKeys + $keys);
} catch (InvalidArgumentException $e) {
Expand Down
15 changes: 10 additions & 5 deletions src/Symfony/Component/Cache/Traits/AbstractAdapterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ trait AbstractAdapterTrait
*/
public function getItem($key)
{
if ($this->deferred) {
$id = $this->getId($key);

if (isset($this->deferred[$key])) {
$this->commit();
}
$id = $this->getId($key);

$f = $this->createCacheItem;
$isHit = false;
Expand All @@ -66,14 +67,18 @@ public function getItem($key)
*/
public function getItems(array $keys = [])
{
if ($this->deferred) {
$this->commit();
}
$ids = [];
$commit = false;

foreach ($keys as $key) {
$ids[] = $this->getId($key);
$commit = $commit || isset($this->deferred[$key]);
}

if ($commit) {
$this->commit();
}

try {
$items = $this->doFetch($ids);
} catch (\Exception $e) {
Expand Down
0