Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Cache.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
20  protected $pathToCacheFile = 'partners';
21 
27  protected $cache;
28 
32  private $serializer;
33 
39  public function __construct(
40  \Magento\Framework\App\Helper\Context $context,
41  \Magento\Framework\Config\CacheInterface $cache,
42  SerializerInterface $serializer = null
43  ) {
44  $this->cache = $cache;
45  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
46  parent::__construct($context);
47  }
48 
54  public function loadPartnersFromCache()
55  {
56  $data = $this->getCache()->load($this->pathToCacheFile);
57  if (false !== $data) {
58  $data = $this->serializer->unserialize($data);
59  }
60  return $data;
61  }
62 
69  public function savePartnersToCache($partners)
70  {
71  return $this->getCache()->save($this->serializer->serialize($partners), $this->pathToCacheFile);
72  }
73 
77  public function getCache()
78  {
79  return $this->cache;
80  }
81 }
$partners
Definition: partners.phtml:11
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Config\CacheInterface $cache, SerializerInterface $serializer=null)
Definition: Cache.php:39