Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.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 PruneCachesSubscriberimplements EventSubscriberInterface{privateconstintPROBABILITY_NUMERATOR =1;privateconstintPROBABILITY_DENOMINATOR =10_000;publicfunction__construct(/** @var iterable<PruneableInterface> */privatereadonlyiterable$prunableCaches, ) { }publicstaticfunctiongetSubscribedEvents():array {return [ TerminateEvent::class =>'pruneCaches', ConsoleTerminateEvent::class =>'pruneCaches', ]; }publicfunctionpruneCaches():void {if (\random_int(1,self::PROBABILITY_DENOMINATOR) >self::PROBABILITY_NUMERATOR) {return; }foreach ($this->prunableCachesas$prunableCache) {$prunableCache->prune(); } }}
Metadata
Metadata
Assignees
Labels
No labels