cache = $cache; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->feedFactory = $feedFactory ?: ObjectManager::getInstance()->get(FeedFactoryInterface::class); } /** * @return array */ public function getFeeds() { if ($this->dataProvider === null) { return []; } $cache = false; if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) { $cache = $this->cache->load($this->dataProvider->getCacheKey()); } if ($cache) { return $this->serializer->unserialize($cache); } $data = $this->dataProvider->getRssData(); if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) { $this->cache->save( $this->serializer->serialize($data), $this->dataProvider->getCacheKey(), ['rss'], $this->dataProvider->getCacheLifetime() ); } return $data; } /** * @param DataProviderInterface $dataProvider * @return $this */ public function setDataProvider(DataProviderInterface $dataProvider) { $this->dataProvider = $dataProvider; return $this; } /** * @return string * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\RuntimeException */ public function createRssXml() { $feed = $this->feedFactory->create($this->getFeeds(), FeedFactoryInterface::FORMAT_RSS); return $feed->getFormattedContent(); } }