Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
Zend_Memory_Manager Class Reference

Public Member Functions

 __construct ($backend=null)
 
 __destruct ()
 
 setMemoryLimit ($newLimit)
 
 getMemoryLimit ()
 
 setMinSize ($newSize)
 
 getMinSize ()
 
 create ($value='')
 
 createLocked ($value='')
 
 unlink (Zend_Memory_Container_Movable $container, $id)
 
 processUpdate (Zend_Memory_Container_Movable $container, $id)
 
 load (Zend_Memory_Container_Movable $container, $id)
 

Detailed Description

Definition at line 44 of file Manager.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $backend = null)

Memory manager constructor

If backend is not specified, then memory objects are never swapped

Parameters
Zend_Cache_Backend$backend
array$backendOptionsassociative array of options for the corresponding backend constructor

Definition at line 161 of file Manager.php.

162  {
163  if ($backend === null) {
164  return;
165  }
166 
167  $this->_backend = $backend;
168  $this->_generateMemManagerId();
169 
170  $memoryLimitStr = trim(ini_get('memory_limit'));
171  if ($memoryLimitStr != '' && $memoryLimitStr != -1) {
172  $this->_memoryLimit = (integer)$memoryLimitStr;
173  switch (strtolower($memoryLimitStr[strlen($memoryLimitStr)-1])) {
174  case 'g':
175  $this->_memoryLimit *= 1024;
176  // Break intentionally omitted
177  case 'm':
178  $this->_memoryLimit *= 1024;
179  // Break intentionally omitted
180  case 'k':
181  $this->_memoryLimit *= 1024;
182  break;
183 
184  default:
185  break;
186  }
187 
188  $this->_memoryLimit = (int)($this->_memoryLimit*2/3);
189  } // No limit otherwise
190  }

◆ __destruct()

__destruct ( )

Object destructor

Clean up backend storage

Definition at line 197 of file Manager.php.

198  {
199  if ($this->_backend !== null) {
200  $this->_backend->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, $this->_tags);
201  }
202  }
const CLEANING_MODE_MATCHING_TAG
Definition: Cache.php:74

Member Function Documentation

◆ create()

create (   $value = '')

Create new Zend_Memory value container

Parameters
string$value
Returns
Zend_Memory_Container_Interface
Exceptions
Zend_Memory_Exception

Definition at line 254 of file Manager.php.

255  {
256  return $this->_create($value, false);
257  }
$value
Definition: gender.phtml:16

◆ createLocked()

createLocked (   $value = '')

Create new Zend_Memory value container, which has value always locked in memory

Parameters
string$value
Returns
Zend_Memory_Container_Interface
Exceptions
Zend_Memory_Exception

Definition at line 267 of file Manager.php.

268  {
269  return $this->_create($value, true);
270  }
$value
Definition: gender.phtml:16

◆ getMemoryLimit()

getMemoryLimit ( )

Get memory grow limit

Returns
integer

Definition at line 222 of file Manager.php.

223  {
224  return $this->_memoryLimit;
225  }

◆ getMinSize()

getMinSize ( )

Get minimum size of values, which may be swapped

Returns
integer

Definition at line 242 of file Manager.php.

243  {
244  return $this->_minSize;
245  }

◆ load()

load ( Zend_Memory_Container_Movable  $container,
  $id 
)

Load value from swap file.

Definition at line 446 of file Manager.php.

447  {
448  $value = $this->_backend->load($this->_managerId . $id, true);
449 
450  // Try to swap other objects if necessary
451  // (do not include specified object into check)
452  $this->_memorySize += strlen($value);
453  $this->_swapCheck();
454 
455  // Add loaded obect to the end of loaded objects list
456  $container->setValue($value);
457 
458  if ($this->_sizes[$id] > $this->_minSize) {
459  // Add object to the end of "unload candidates list"
460  $this->_unloadCandidates[$id] = $container;
461  }
462  }
$id
Definition: fieldset.phtml:14
$value
Definition: gender.phtml:16

◆ processUpdate()

processUpdate ( Zend_Memory_Container_Movable  $container,
  $id 
)

Process value update

This method is automatically invoked by memory container only once per "modification session", but user may call memory container touch() method several times depending on used algorithm. So we have to use this check to optimize this case.

Definition at line 334 of file Manager.php.

335  {
342  if ($container === $this->_lastModified) {
343  return;
344  }
345 
346  // Remove just updated object from list of candidates to unload
347  if( isset($this->_unloadCandidates[$id])) {
348  unset($this->_unloadCandidates[$id]);
349  }
350 
351  // Reduce used memory mark
352  $this->_memorySize -= $this->_sizes[$id];
353 
354  // Commit changes of previously modified object if necessary
355  $this->_commit();
356 
357  $this->_lastModified = $container;
358  }
$id
Definition: fieldset.phtml:14

◆ setMemoryLimit()

setMemoryLimit (   $newLimit)

Set memory grow limit

Parameters
integer$newLimit
Exceptions
Zend_Exception

Definition at line 210 of file Manager.php.

211  {
212  $this->_memoryLimit = $newLimit;
213 
214  $this->_swapCheck();
215  }

◆ setMinSize()

setMinSize (   $newSize)

Set minimum size of values, which may be swapped

Parameters
integer$newSize

Definition at line 232 of file Manager.php.

233  {
234  $this->_minSize = $newSize;
235  }

◆ unlink()

unlink ( Zend_Memory_Container_Movable  $container,
  $id 
)

Unlink value container from memory manager

Used by Memory container destroy() method

Definition at line 310 of file Manager.php.

311  {
312  if ($this->_lastModified === $container) {
313  // Drop all object modifications
314  $this->_lastModified = null;
315  unset($this->_sizes[$id]);
316  return;
317  }
318 
319  if (isset($this->_unloadCandidates[$id])) {
320  unset($this->_unloadCandidates[$id]);
321  }
322 
323  $this->_memorySize -= $this->_sizes[$id];
324  unset($this->_sizes[$id]);
325  }
$id
Definition: fieldset.phtml:14

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