Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Cache Class Reference
Inheritance diagram for Cache:
AbstractHelper

Public Member Functions

 __construct (\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Config\CacheInterface $cache, SerializerInterface $serializer=null)
 
 loadPartnersFromCache ()
 
 savePartnersToCache ($partners)
 
 getCache ()
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Protected Attributes

 $pathToCacheFile = 'partners'
 
 $cache
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Detailed Description

Cache helper

Definition at line 15 of file Cache.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Helper\Context  $context,
\Magento\Framework\Config\CacheInterface  $cache,
SerializerInterface  $serializer = null 
)
Parameters
\Magento\Framework\App\Helper\Context$context
\Magento\Framework\Config\CacheInterface$cache
SerializerInterface$serializer

Definition at line 39 of file Cache.php.

43  {
44  $this->cache = $cache;
45  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
46  parent::__construct($context);
47  }

Member Function Documentation

◆ getCache()

getCache ( )
Returns
\Magento\Framework\Config\CacheInterface

Definition at line 77 of file Cache.php.

78  {
79  return $this->cache;
80  }

◆ loadPartnersFromCache()

loadPartnersFromCache ( )

Load partners from cache

Returns
array

Definition at line 54 of file Cache.php.

55  {
56  $data = $this->getCache()->load($this->pathToCacheFile);
57  if (false !== $data) {
58  $data = $this->serializer->unserialize($data);
59  }
60  return $data;
61  }

◆ savePartnersToCache()

savePartnersToCache (   $partners)

Save composer packages available for update to cache

Parameters
string$partners
Returns
bool

Definition at line 69 of file Cache.php.

70  {
71  return $this->getCache()->save($this->serializer->serialize($partners), $this->pathToCacheFile);
72  }
$partners
Definition: partners.phtml:11

Field Documentation

◆ $cache

$cache
protected

Definition at line 27 of file Cache.php.

◆ $pathToCacheFile

$pathToCacheFile = 'partners'
protected

Definition at line 20 of file Cache.php.


The documentation for this class was generated from the following file: