Display cache item, send headers if necessary.

@param \PageCache\Storage\CacheItemInterface $item
771224
private function displayItem(CacheItemInterface $item)
    {
        $isDryRun = $this->config()->isDryRunMode();
        $itemContent = $item->getContent();

        if (empty($itemContent)) {
            $this->log(__METHOD__ . ' Empty cache item found, skipping cache.', print_r($item, true));
            return;
        }

        $this->httpHeaders
            ->setLastModified($item->getLastModified())
            ->setExpires($item->getExpiresAt())
            ->setETag($item->getETagString());

        // Decide if sending headers from Config
        // Send headers (if not disabled) and process If-Modified-Since header
        if ($this->config->isSendHeaders()) {
            $logHeaders = sprintf(
                '%s: %s, %s: %s,%s: %s',
                HttpHeaders::HEADER_LAST_MODIFIED,
                $item->getLastModified()->format(HttpHeaders::DATE_FORMAT_CREATE),
                HttpHeaders::HEADER_EXPIRES,
                $item->getExpiresAt()->format(HttpHeaders::DATE_FORMAT_CREATE),
                HttpHeaders::HEADER_ETAG,
                $item->getETagString()
            );
            $this->log(__METHOD__ . ' uri:' . $_SERVER['REQUEST_URI']
                . '; Headers {' . $logHeaders . '}');

            if (!$isDryRun) {
                $this->httpHeaders->send();
                $this->log(
                    __METHOD__ . ' Headers sent: ' . PHP_EOL . implode(
                        PHP_EOL,
                        $this->httpHeaders->getSentHeaders()
                    )
                );
            }

            // Check if conditions for the If-Modified-Since header are met
            if ($this->httpHeaders->checkIfNotModified()) {
                if (!$isDryRun) {
                    $this->httpHeaders->sendNotModifiedHeader();
                    $this->log(__METHOD__ . ' 304 Not Modified header was set. Exiting w/o content.');
                    $this->log(__METHOD__ . ' Response status: ' . http_response_code());
                    exit();
                }
                $this->log(__METHOD__ . ' 304 Not Modified header was set. Not exiting w/o content - Dry Mode.');
            }
        }

        // Show cached content
        $this->log(__METHOD__ . ' Cache item found: ' . $this->getCurrentKey());
        $this->log(__METHOD__ . ' Response status: ' . http_response_code());

        if (!$isDryRun) {
            echo $itemContent;
            exit();
        }
    }
44611
protected function setActive(ItemInterface $item = null)
    {
        if ($item) {
            $this->setActive($item->getParent());
            $item->setAttribute('class', $item->getAttribute('class', '') . ' active');
        }
    }
556074
protected function storeItemInCache(CacheItemInterface $item)
    {
        $this->cache->setRawValue(
            $this->getHierarchyKey($item->getKey()),
            $item->get(),
            $item->getTags(),
            $item->getExpirationTimestamp()
        );
    }
442129
public function monitor($item)
    {
        if ($item instanceof PoolInterface) {
            $item->addListener(PoolRunEvent::POOL_RUN_ADDED, [$this, 'onPoolRunAdded']);
            $item->addListener(PoolRunEvent::UPDATED, [$this, 'onPoolUpdated']);
            array_map([$this, 'monitor'], $item->getAll());
        }
        if ($item instanceof RunInterface) {
            $item->addListener(RunEvent::STARTED, [$this, 'onRunStarted']);
            $item->addListener(RunEvent::SUCCESSFUL, [$this, 'onRunSuccessful']);
            $item->addListener(RunEvent::FAILED, [$this, 'onRunFailed']);
            $item->addListener(RunEvent::COMPLETED, [$this, 'onRunCompleted']);
        }
    }
206530
protected function isPageIndexable(Item $item)
    {

        // TODO do we still need this?
        // shouldn't those be sorted out by the record monitor / garbage collector already?

        $isIndexable = true;
        $record = $item->getRecord();

        if (isset($GLOBALS['TCA']['pages']['ctrl']['enablecolumns']['disabled'])
            && $record[$GLOBALS['TCA']['pages']['ctrl']['enablecolumns']['disabled']]
        ) {
            $isIndexable = false;
        }

        return $isIndexable;
    }
222981
public function save(CacheItemInterface $item)
    {
        if (! $item instanceof CacheItem) {
            throw new InvalidArgumentException('$item must be an instance of ' . CacheItem::class);
        }

        $this->validateKey($item->getKey());

        try {
            $options = false;
            $expiration = $item->getExpiration();

            // @todo I can't see any way to set the TTL on an individual item except by temporarily overwriting the
            //       option on the storage adapter. Not sure if all storage adapters will support this...
            if ($expiration instanceof DateTime) {
                $options = $this->storage->getOptions();
                $new = clone $options;
                $interval = $expiration->diff(new DateTime(), true);
                $new->setTtl($interval->format('%s'));
                $this->storage->setOptions($new);
            }

            $saved = $this->storage->setItem($item->getKey(), $item->get());

            if ($options) {
                $this->storage->setOptions($options);
            }

        } catch (Exception\InvalidArgumentException $e) {
            throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);

        } catch (Exception\ExceptionInterface $e) {
            throw new CacheException($e->getMessage(), $e->getCode(), $e);
        }

        return $saved;
    }
1156599
public function set(CacheableInterface $item)
    {
        $this->connection->set($item->getHashKey(), $item->getDataForCache(), $item->getTtl());
    }
835518
public function addItem($item)
    {
        $indentation = $this->indent($this->indentation);

        $this->buffer[] = $indentation.$item;
    }
282980
@Override
    public void itemCacheSetManagedReference(AbstractItem item)
    {
        // Defect 601995
        if (item != null)
        {
            _itemCacheManagedReference = item;
        }
        else
        {
            // If our cache reference is being set to null then 
            // use the new named class instead.
            _itemCacheManagedReference = NULL_CACHE_REF;
        }
    }
1048500
public function save(CacheItemInterface $item)
    {
        $metadata = $item->getMetadata();
        $metadata[ 'data' ] = $item->get();

        if ( ! $this->redis->set($this->prefixKey . $item->getKey(), serialize($metadata), $metadata[ 'ttl' ])) {
            return false;
        } elseif ($metadata[ 'ttl' ] > 0) {
            $this->redis->expireAt($this->prefixKey . $item->getKey(), $metadata[ 'etime' ]);
        }

        return true;
    }
806036
public function prePersist(Item $item, LifecycleEventArgs $event)
    {
        $interaction = $item->getInteraction();
        if (null !== $interaction) {
            $event->getEntityManager()->persist($interaction);
        }
    }
427484
protected function renderItemIcon($item)
    {
        $iconClass = ArrayHelper::getValue($item, 'icon');
        if ($iconClass !== null) {
            $class = [$this->iconClass];
            Html::addCssClass($class, $iconClass);
            return Html::tag('i', '', ['class' => $class]);
        } else {
            return '';
        }
    }
776009
protected function printFeedbackItem(string $item)
    {
        echo $item;
        ++$this->column;
        ++$this->casesProcessed;
        if ($this->column === $this->maxColumn) {
            echo $this->getProgress();
            $this->println();
        }
    }
717165
private function _renderItemSeparated (\stdClass $item) {
		$result = '<script type="text/javascript"';
		if ($item->async) $result .= ' async="async"';
		if ($item->async) $result .= ' defer="defer"';
		if (!$item->external && self::$fileChecking) {
			$fullPath = $this->getAppRoot() . $item->path;
			if (!file_exists($fullPath)) {
				$this->log("File not found in CSS view rendering process ('$fullPath').", 'error');
			}
		}
		$result .= ' src="' . $item->src . '"></script>';
		return $result;
	}
65138
public final function saveDeferred(CacheItemInterface $item)
   {
        if (in_array($item, $this->queue)) {
            return false;
        }
        $this->queue[] = $item;
        return true;
   }
30298
private function saveContentInCache($item, array $content)
    {
        if (null !== $this->cache && null !== $item) {
            $item->set($this->contentCache);
            $this->cache->save($item);
        }

        return $content;
    }
847807
private function getFreshDataWithCache(QueueItem $item)
    {
        $sdk = $this->getSdk($item);
        $entity = $sdk->get($item->getId())->wait(true);
        if (false === $this->shouldCacheEntity($item->getType(), $item->getId())) {
            return $entity;
        }
        if ($entity) {
            $this->logger->debug('Saving to cache', [
                'type' => $item->getType(),
                'id' => $item->getId(),
            ]);
            $this->cache->save(
                $this->getKeyFromQueueItem($item),
                $this->serializer->serialize($entity, 'json', ['type' => true]),
                $this->lifetime
            );
        } else {
            $this->logger->debug('404 from SDK', [
                'type' => $item->getType(),
                'id' => $item->getId(),
            ]);
        }

        return $entity;
    }