Skip to content

Commit 5996644

Browse files
committed
📦 CacheAttributeListener is now resettable to prevent memory leaks
1 parent c7f5044 commit 5996644

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143

144144
->set('controller.cache_attribute_listener', CacheAttributeListener::class)
145145
->tag('kernel.event_subscriber')
146+
->tag('kernel.reset', ['method' => 'reset'])
146147

147148
;
148149
};

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"symfony/error-handler": "^6.1|^7.0",
2727
"symfony/event-dispatcher": "^5.4|^6.0|^7.0",
2828
"symfony/http-foundation": "^6.4|^7.0",
29-
"symfony/http-kernel": "^6.4",
29+
"symfony/http-kernel": "^6.4.23",
3030
"symfony/polyfill-mbstring": "~1.0",
3131
"symfony/filesystem": "^5.4|^6.0|^7.0",
3232
"symfony/finder": "^5.4|^6.0|^7.0",

src/Symfony/Component/HttpKernel/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
6.4
55
---
66

7+
* `Symfony\Component\HttpKernel\EventListener\CacheAttributeListener` is now resettable to prevent memory leaks
78
* Support backed enums in #[MapQueryParameter]
89
* `BundleInterface` no longer extends `ContainerAwareInterface`
910
* Add optional `$className` parameter to `ControllerEvent::getAttributes()`

src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
2020
use Symfony\Component\HttpKernel\Event\ResponseEvent;
2121
use Symfony\Component\HttpKernel\KernelEvents;
22+
use Symfony\Contracts\Service\ResetInterface;
2223

2324
/**
2425
* Handles HTTP cache headers configured via the Cache attribute.
2526
*
2627
* @author Fabien Potencier <fabien@symfony.com>
2728
*/
28-
class CacheAttributeListener implements EventSubscriberInterface
29+
class CacheAttributeListener implements EventSubscriberInterface, ResetInterface
2930
{
3031
/**
3132
* @var \SplObjectStorage<Request, \DateTimeInterface>
@@ -178,6 +179,12 @@ public static function getSubscribedEvents(): array
178179
];
179180
}
180181

182+
public function reset(): void
183+
{
184+
$this->lastModified = new \SplObjectStorage();
185+
$this->etags = new \SplObjectStorage();
186+
}
187+
181188
private function getExpressionLanguage(): ExpressionLanguage
182189
{
183190
return $this->expressionLanguage ??= class_exists(ExpressionLanguage::class)

0 commit comments

Comments
 (0)