Skip to content

Commit b3f3bda

Browse files
authored
Merge pull request #12400 from isaackaara/fix/cache-mode-refresh-put
Fix Cache::MODE_REFRESH not writing to query cache
2 parents a9f633e + eeeb10a commit b3f3bda

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/Cache/DefaultQueryCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, mixed $result, ar
215215
throw FeatureNotImplemented::partialEntities();
216216
}
217217

218-
if (! ($key->cacheMode & Cache::MODE_PUT)) {
218+
if (! ($key->cacheMode & Cache::MODE_PUT) && ! ($key->cacheMode & Cache::MODE_REFRESH)) {
219219
return false;
220220
}
221221

tests/Tests/ORM/Cache/DefaultQueryCacheTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,28 @@ public function testIgnoreCacheNonPutMode(): void
496496
self::assertFalse($this->queryCache->put($key, $rsm, $result));
497497
}
498498

499+
public function testRefreshModeWritesToCache(): void
500+
{
501+
$result = [];
502+
$rsm = new ResultSetMappingBuilder($this->em);
503+
$metadata = $this->em->getClassMetadata(Country::class);
504+
$key = new QueryCacheKey('query.key1', 0, Cache::MODE_REFRESH);
505+
506+
$rsm->addRootEntityFromClassMetadata(Country::class, 'c');
507+
508+
for ($i = 0; $i < 2; $i++) {
509+
$name = 'Country ' . $i;
510+
$entity = new Country($name);
511+
$result[] = $entity;
512+
513+
$metadata->setFieldValue($entity, 'id', $i);
514+
$this->em->getUnitOfWork()->registerManaged($entity, ['id' => $i], ['name' => $name]);
515+
}
516+
517+
self::assertTrue($this->queryCache->put($key, $rsm, $result));
518+
self::assertArrayHasKey('put', $this->region->calls);
519+
}
520+
499521
public function testGetShouldIgnoreOldQueryCacheEntryResult(): void
500522
{
501523
$rsm = new ResultSetMappingBuilder($this->em);

0 commit comments

Comments
 (0)