Skip to content
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 null/empty returns for findOneBy #11584

Open
wants to merge 4 commits into
base: 3.3.x
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion src/Cache/DefaultQueryCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public function get(QueryCacheKey $key, ResultSetMapping $rsm, array $hints = []
$generateKeys = static fn (array $entry): EntityCacheKey => new EntityCacheKey($cm->rootEntityName, $entry['identifier']);

$cacheKeys = new CollectionCacheEntry(array_map($generateKeys, $cacheEntry->result));
$entries = $region->getMultiple($cacheKeys) ?? [];
$entries = $region->getMultiple($cacheKeys);

if ($entries === null) {
return null;
}

// @TODO - move to cache hydration component
foreach ($cacheEntry->result as $index => $entry) {
Expand Down
10 changes: 7 additions & 3 deletions src/Cache/Persister/Entity/AbstractEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,21 @@
if ($result !== null) {
$this->cacheLogger?->queryCacheHit($this->regionName, $queryKey);

if (empty($result)) {
return null;

Check warning on line 313 in src/Cache/Persister/Entity/AbstractEntityPersister.php

View check run for this annotation

Codecov / codecov/patch

src/Cache/Persister/Entity/AbstractEntityPersister.php#L313

Added line #L313 was not covered by tests
}

return $result[0];
}

$result = $this->persister->load($criteria, $entity, $assoc, $hints, $lockMode, $limit, $orderBy);

if ($result === null) {
return null;
$cached = $queryCache->put($queryKey, $rsm, []);
} else {
$cached = $queryCache->put($queryKey, $rsm, [$result]);
}

$cached = $queryCache->put($queryKey, $rsm, [$result]);

$this->cacheLogger?->queryCacheMiss($this->regionName, $queryKey);

if ($cached) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function testLoadFromDatabaseWhenEntityMissing(): void
self::assertCount(2, $result2);

self::assertEquals(5, $this->secondLevelCacheLogger->getPutCount());
self::assertEquals(3, $this->secondLevelCacheLogger->getMissCount());
self::assertEquals(2, $this->secondLevelCacheLogger->getMissCount());
self::assertEquals(2, $this->secondLevelCacheLogger->getRegionPutCount($this->getDefaultQueryRegionName()));
self::assertEquals(2, $this->secondLevelCacheLogger->getRegionMissCount($this->getDefaultQueryRegionName()));

Expand Down
Loading