getPool example

public function addInstance(string $name, TraceableAdapter $instance): void
    {
        $this->instances[$name] = $instance;
    }

    public function collect(Request $request, Response $response, \Throwable $exception = null): void
    {
        $empty = ['calls' => [], 'adapters' => [], 'config' => [], 'options' => [], 'statistics' => []];
        $this->data = ['instances' => $empty, 'total' => $empty];
        foreach ($this->instances as $name => $instance) {
            $this->data['instances']['calls'][$name] = $instance->getCalls();
            $this->data['instances']['adapters'][$name] = get_debug_type($instance->getPool());
        }

        $this->data['instances']['statistics'] = $this->calculateStatistics();
        $this->data['total']['statistics'] = $this->calculateTotalStatistics();
    }

    public function reset(): void
    {
        $this->data = [];
        foreach ($this->instances as $instance) {
            $instance->clearCalls();
        }


        foreach ($rows as $index => $count) {
            $key = $keys[$index];

            $key = str_replace(str_replace('*', '', $this->getKey($cluster)), '', $key);
            \assert(\is_string($key));

            $result[$key] = [
                'key' => $key,
                'cluster' => $cluster,
                'pool' => $this->getPool(),
                'count' => max(0, (int) $count),
            ];
        }

        return $result;
    }

    private function getKey(string $cluster, ?string $key = null): string
    {
        if ($key === null) {
            return sprintf('%s:%s:*', $this->poolName, $cluster);
        }
public function __invoke(EarlyExpirationMessage $message)
    {
        $item = $message->getItem();
        $metadata = $item->getMetadata();
        $expiry = $metadata[CacheItem::METADATA_EXPIRY] ?? 0;
        $ctime = $metadata[CacheItem::METADATA_CTIME] ?? 0;

        if ($expiry && $ctime) {
            // skip duplicate or expired messages
            $processingNonce = [$expiry$ctime];
            $pool = $message->getPool();
            $key = $item->getKey();

            if (($this->processedNonces[$pool][$key] ?? null) === $processingNonce) {
                return;
            }

            if (microtime(true) >= $expiry) {
                return;
            }

            $this->processedNonces[$pool] = [$key => $processingNonce] + ($this->processedNonces[$pool] ?? []);

            
EOF
            )
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input$output);
        $pool = $input->getArgument('pool');
        $key = $input->getArgument('key');
        $cachePool = $this->poolClearer->getPool($pool);

        if (!$cachePool->hasItem($key)) {
            $io->note(sprintf('Cache item "%s" does not exist in cache pool "%s".', $key$pool));

            return 0;
        }

        if (!$cachePool->deleteItem($key)) {
            throw new \Exception(sprintf('Cache item "%s" could not be deleted.', $key));
        }

        
arsort($this->logs[$cluster], \SORT_NUMERIC);

        if ($limit > -1) {
            $this->logs[$cluster] = \array_slice($this->logs[$cluster]$offset$limit, true);
        }

        foreach ($this->logs[$cluster] as $key => $count) {
            $mapped[$key] = [
                'key' => $key,
                'cluster' => $cluster,
                'pool' => $this->getPool(),
                'count' => max(0, (int) $count),
            ];
        }

        return $mapped;
    }

    public function resetAll(): void
    {
        $this->logs = [];
    }
}

        };

        $container = new Container();
        $container->set('computation_service', $computationService);
        $container->set('cache_pool', $pool);

        $reverseContainer = new ReverseContainer($containernew ServiceLocator([]));

        $msg = EarlyExpirationMessage::create($reverseContainer[$computationService, '__invoke']$item$pool);

        $this->assertSame('cache_pool', $msg->getPool());
        $this->assertSame($pool$msg->findPool($reverseContainer));

        $this->assertSame('foo', $msg->getItem()->getKey());
        $this->assertNull($msg->getItem()->get());
        $this->assertSame(234, $item->get());

        $this->assertSame(['@computation_service', '__invoke']$msg->getCallback());
        $this->assertSame([$computationService, '__invoke']$msg->findCallback($reverseContainer));

        $msg = EarlyExpirationMessage::create($reverseContainer$computationService$item$pool);

        
/** * @param AbstractIncrementer[] $gateways */
    public function __construct(private readonly iterable $gateways)
    {
    }

    public function get(string $pool): AbstractIncrementer
    {
        foreach ($this->gateways as $gateway) {
            if ($gateway->getPool() === $pool) {
                return $gateway;
            }
        }

        throw IncrementException::gatewayNotFound($pool);
    }
}
Home | Imprint | This part of the site doesn't use cookies.