How to cache custom data programmatically?

@dmitry_fedyuk is there anyway I can cache data in Magento 2?

Let’s example: I am reading XML file youtube video and display it on site, I want to cache it, how to do in magento 2?

public function getVideo()
$xmlElement = simplexml_load_string($xmlContent,‘SimpleXMLElement’);
$urls =[];
foreach($xmlElement->entry as $entry)
$url = $entry->link[‘href’];
$url = explode(’?v=’,$url);

  return $urls;


Use \Magento\Framework\App\CacheInterface.

1 Like