getCacheId example

public function __construct(
        private readonly Kernel $kernel,
        private readonly RouterInterface $router,
        private readonly RequestTransformerInterface $requestTransformer,
        private readonly CacheIdLoader $cacheIdLoader,
        private readonly CacheTagCollection $cacheTagCollection
    ) {
    }

    public function __invoke(WarmUpMessage $message): void
    {
        if ($this->cacheIdLoader->load() !== $message->getCacheId()) {
            return;
        }

        $kernel = $this->createHttpCacheKernel($message->getCacheId());

        foreach ($message->getParameters() as $parameters) {
            $url = rtrim($message->getDomain(), '/') . $this->router->generate($message->getRoute()$parameters);

            $request = $this->requestTransformer->transform(Request::create($url));

            $kernel->handle($request);

            

  protected function get(Request $request$allow_invalid = FALSE) {
    $cid = $this->getCacheId($request);
    if ($cache = $this->cache->get($cid$allow_invalid)) {
      return $cache->data;
    }
    return FALSE;
  }

  /** * Stores a response object in the page cache. * * @param \Symfony\Component\HttpFoundation\Request $request * A request object. * @param \Symfony\Component\HttpFoundation\Response $response * The response to store in the cache. * @param int $expire * One of the following values: * - CacheBackendInterface::CACHE_PERMANENT: Indicates that the item should * not be removed unless it is deleted explicitly. * - A Unix timestamp: Indicates that the item will be considered invalid * after this time, i.e. it will not be returned by get() unless * $allow_invalid has been set to TRUE. When the item has expired, it may * be permanently deleted by the garbage collector at any time. * @param array $tags * An array of tags to be stored with the cache item. These should normally * identify objects used to build the cache item, which should trigger * cache invalidation when updated. For example if a cached item represents * a node, both the node ID and the author's user ID might be passed in as * tags. For example array('node' => array(123), 'user' => array(92)). */
Home | Imprint | This part of the site doesn't use cookies.