forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use NullCacheItemPool when using a Paginator.
This fixes a bug where Doctrine would recreate the DQL to SQL parsing cache on every request which would fill up OPCache with duplicates. We now use a "Null" cache implementation instead of calling Query::expireQueryCache(). @see doctrine#9917
- Loading branch information
Charles Megard
committed
Oct 4, 2022
1 parent
cbf141f
commit 89722a6
Showing
3 changed files
with
168 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Cache; | ||
|
||
use Psr\Cache\CacheItemInterface; | ||
|
||
/** | ||
* @internal this class is used as a workaround for a cache issue. | ||
* | ||
* @see https://github.com/doctrine/orm/pull/10095 | ||
*/ | ||
final class NullCacheItem implements CacheItemInterface | ||
{ | ||
public function getKey(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return mixed | ||
*/ | ||
public function get() | ||
{ | ||
return null; | ||
} | ||
|
||
public function isHit(): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function set($value): self | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function expiresAt($expiration): self | ||
{ | ||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function expiresAfter($time): self | ||
{ | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ORM\Cache; | ||
|
||
use Closure; | ||
use Doctrine\Common\Cache\Psr6\CacheItem; | ||
use Psr\Cache\CacheItemInterface; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
use Traversable; | ||
|
||
/** | ||
* @internal this class is used as a workaround for a cache issue. | ||
* | ||
* @see https://github.com/doctrine/orm/pull/10095 | ||
*/ | ||
final class NullCacheItemPool implements CacheItemPoolInterface | ||
{ | ||
/** @var Closure|null */ | ||
private static $createCacheItem; | ||
|
||
public function __construct() | ||
{ | ||
self::$createCacheItem ?? self::$createCacheItem = Closure::bind( | ||
static function (string $key) { | ||
return new NullCacheItem(); | ||
}, | ||
null, | ||
CacheItem::class | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getItem($key): CacheItemInterface | ||
{ | ||
return (self::$createCacheItem)($key); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getItems(array $keys = []): Traversable | ||
{ | ||
return $this->generateItems($keys); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function hasItem($key): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function clear(string $prefix = ''): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function deleteItem($key): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function deleteItems(array $keys): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function save(CacheItemInterface $item): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function saveDeferred(CacheItemInterface $item): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function commit(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @param array<string> $keys | ||
* | ||
* @return Traversable<CacheItem> | ||
*/ | ||
private function generateItems(array $keys): Traversable | ||
{ | ||
$f = self::$createCacheItem; | ||
|
||
foreach ($keys as $key) { | ||
yield $key => $f($key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters