-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Open
Description
Description
I want a subscriber added to the framework bundle that will sometimes prune caches at the end of a request.
You should be able to configure the PROBABILITY_NUMERATOR and PROBABILITY_DENOMINATOR exactly like the session.gc ini settings.
Example
class PruneCachesSubscriber implements EventSubscriberInterface
{
private const int PROBABILITY_NUMERATOR = 1;
private const int PROBABILITY_DENOMINATOR = 10_000;
public function __construct(
/** @var iterable<PruneableInterface> */
private readonly iterable $prunableCaches,
) {
}
public static function getSubscribedEvents(): array
{
return [
TerminateEvent::class => 'pruneCaches',
ConsoleTerminateEvent::class => 'pruneCaches',
];
}
public function pruneCaches(): void
{
if (\random_int(1, self::PROBABILITY_DENOMINATOR) > self::PROBABILITY_NUMERATOR) {
return;
}
foreach ($this->prunableCaches as $prunableCache) {
$prunableCache->prune();
}
}
}Metadata
Metadata
Assignees
Labels
No labels