Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Cache_Backend_Xcache Class Reference
Inheritance diagram for Zend_Cache_Backend_Xcache:
Zend_Cache_Backend Zend_Cache_Backend_Interface

Public Member Functions

 __construct (array $options=array())
 
 load ($id, $doNotTestCacheValidity=false)
 
 test ($id)
 
 save ($data, $id, $tags=array(), $specificLifetime=false)
 
 remove ($id)
 
 clean ($mode=Zend_Cache::CLEANING_MODE_ALL, $tags=array())
 
 isAutomaticCleaningAvailable ()
 
- Public Member Functions inherited from Zend_Cache_Backend
 __construct (array $options=array())
 
 setDirectives ($directives)
 
 setOption ($name, $value)
 
 getOption ($name)
 
 getLifetime ($specificLifetime)
 
 isAutomaticCleaningAvailable ()
 
 getTmpDir ()
 
- Public Member Functions inherited from Zend_Cache_Backend_Interface
 setDirectives ($directives)
 

Data Fields

const TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::clean() : tags are unsupported by the Xcache backend'
 
const TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::save() : tags are unsupported by the Xcache backend'
 

Protected Attributes

 $_options
 
- Protected Attributes inherited from Zend_Cache_Backend
 $_directives
 
 $_options = array()
 

Additional Inherited Members

- Protected Member Functions inherited from Zend_Cache_Backend
 _isGoodTmpDir ($dir)
 
 _loggerSanity ()
 
 _log ($message, $priority=4)
 

Detailed Description

Definition at line 41 of file Xcache.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $options = array())

Constructor

Parameters
array$optionsassociative array of options
Exceptions
Zend_Cache_Exception
Returns
void

Definition at line 73 of file Xcache.php.

74  {
75  if (!extension_loaded('xcache')) {
76  Zend_Cache::throwException('The xcache extension must be loaded for using this backend !');
77  }
78  parent::__construct($options);
79  }
static throwException($msg, Exception $e=null)
Definition: Cache.php:205

Member Function Documentation

◆ clean()

clean (   $mode = Zend_Cache::CLEANING_MODE_ALL,
  $tags = array() 
)

Clean some cache records

Available modes are : 'all' (default) => remove all cache entries ($tags is not used) 'old' => unsupported 'matchingTag' => unsupported 'notMatchingTag' => unsupported 'matchingAnyTag' => unsupported

Parameters
string$modeclean mode
array$tagsarray of tags
Exceptions
Zend_Cache_Exception
Returns
boolean true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 167 of file Xcache.php.

168  {
169  switch ($mode) {
171  // Necessary because xcache_clear_cache() need basic authentification
172  $backup = array();
173  if (isset($_SERVER['PHP_AUTH_USER'])) {
174  $backup['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER'];
175  }
176  if (isset($_SERVER['PHP_AUTH_PW'])) {
177  $backup['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW'];
178  }
179  if ($this->_options['user']) {
180  $_SERVER['PHP_AUTH_USER'] = $this->_options['user'];
181  }
182  if ($this->_options['password']) {
183  $_SERVER['PHP_AUTH_PW'] = $this->_options['password'];
184  }
185 
186  $cnt = xcache_count(XC_TYPE_VAR);
187  for ($i=0; $i < $cnt; $i++) {
188  xcache_clear_cache(XC_TYPE_VAR, $i);
189  }
190 
191  if (isset($backup['PHP_AUTH_USER'])) {
192  $_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER'];
193  $_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW'];
194  }
195  return true;
196  break;
198  $this->_log("Zend_Cache_Backend_Xcache::clean() : CLEANING_MODE_OLD is unsupported by the Xcache backend");
199  break;
203  $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND);
204  break;
205  default:
206  Zend_Cache::throwException('Invalid mode for clean() method');
207  break;
208  }
209  }
const CLEANING_MODE_OLD
Definition: Cache.php:73
_log($message, $priority=4)
Definition: Backend.php:273
const CLEANING_MODE_NOT_MATCHING_TAG
Definition: Cache.php:75
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
const CLEANING_MODE_ALL
Definition: Cache.php:72
static throwException($msg, Exception $e=null)
Definition: Cache.php:205
const CLEANING_MODE_MATCHING_ANY_TAG
Definition: Cache.php:76
const CLEANING_MODE_MATCHING_TAG
Definition: Cache.php:74
$i
Definition: gallery.phtml:31

◆ isAutomaticCleaningAvailable()

isAutomaticCleaningAvailable ( )

Return true if the automatic cleaning is available for the backend

Returns
boolean

Definition at line 216 of file Xcache.php.

217  {
218  return false;
219  }

◆ load()

load (   $id,
  $doNotTestCacheValidity = false 
)

Test if a cache is available for the given id and (if yes) return it (false else)

WARNING $doNotTestCacheValidity=true is unsupported by the Xcache backend

Parameters
string$idcache id
boolean$doNotTestCacheValidityif set to true, the cache validity won't be tested
Returns
string cached datas (or false)

Implements Zend_Cache_Backend_Interface.

Definition at line 90 of file Xcache.php.

91  {
92  if ($doNotTestCacheValidity) {
93  $this->_log("Zend_Cache_Backend_Xcache::load() : \$doNotTestCacheValidity=true is unsupported by the Xcache backend");
94  }
95  $tmp = xcache_get($id);
96  if (is_array($tmp)) {
97  return $tmp[0];
98  }
99  return false;
100  }
$id
Definition: fieldset.phtml:14
_log($message, $priority=4)
Definition: Backend.php:273

◆ remove()

remove (   $id)

Remove a cache record

Parameters
string$idcache id
Returns
boolean true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 147 of file Xcache.php.

148  {
149  return xcache_unset($id);
150  }
$id
Definition: fieldset.phtml:14

◆ save()

save (   $data,
  $id,
  $tags = array(),
  $specificLifetime = false 
)

Save some string datas into a cache record

Note : $data is always "string" (serialization is done by the core not by the backend)

Parameters
string$datadatas to cache
string$idcache id
array$tagsarray of strings, the cache record will be tagged by each string entry
int$specificLifetimeif != false, set a specific lifetime for this cache record (null => infinite lifetime)
Returns
boolean true if no problem

Implements Zend_Cache_Backend_Interface.

Definition at line 131 of file Xcache.php.

132  {
133  $lifetime = $this->getLifetime($specificLifetime);
134  $result = xcache_set($id, array($data, time()), $lifetime);
135  if (count($tags) > 0) {
136  $this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND);
137  }
138  return $result;
139  }
$id
Definition: fieldset.phtml:14
_log($message, $priority=4)
Definition: Backend.php:273
getLifetime($specificLifetime)
Definition: Backend.php:143

◆ test()

test (   $id)

Test if a cache is available or not (for the given id)

Parameters
string$idcache id
Returns
mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record

Implements Zend_Cache_Backend_Interface.

Definition at line 108 of file Xcache.php.

109  {
110  if (xcache_isset($id)) {
111  $tmp = xcache_get($id);
112  if (is_array($tmp)) {
113  return $tmp[1];
114  }
115  }
116  return false;
117  }
$id
Definition: fieldset.phtml:14

Field Documentation

◆ $_options

$_options
protected
Initial value:
= array(
'user' => null,
'password' => null
)

Definition at line 61 of file Xcache.php.

◆ TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND

const TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::clean() : tags are unsupported by the Xcache backend'

Log message

Definition at line 47 of file Xcache.php.

◆ TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND

const TAGS_UNSUPPORTED_BY_SAVE_OF_XCACHE_BACKEND = 'Zend_Cache_Backend_Xcache::save() : tags are unsupported by the Xcache backend'

Definition at line 48 of file Xcache.php.


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