23 #require_once 'Zend/Memory/Container/Movable.php'; 26 #require_once 'Zend/Memory/Container/Locked.php'; 29 #require_once 'Zend/Memory/AccessController.php'; 51 private $_backend =
null;
60 private $_memoryLimit = -1;
69 private $_minSize = 16384;
76 private $_memorySize = 0;
97 private $_unloadCandidates = array();
108 private $_sizes = array();
120 private $_lastModified =
null;
139 private function _generateMemManagerId()
147 $this->_managerId = uniqid(
'ZendMemManager',
true);
148 $this->_tags = array($this->_managerId);
149 $this->_managerId .=
'_';
163 if ($backend ===
null) {
167 $this->_backend = $backend;
168 $this->_generateMemManagerId();
170 $memoryLimitStr = trim(
ini_get(
'memory_limit'));
171 if ($memoryLimitStr !=
'' && $memoryLimitStr != -1) {
172 $this->_memoryLimit = (integer)$memoryLimitStr;
173 switch (strtolower($memoryLimitStr[strlen($memoryLimitStr)-1])) {
175 $this->_memoryLimit *= 1024;
178 $this->_memoryLimit *= 1024;
181 $this->_memoryLimit *= 1024;
188 $this->_memoryLimit = (int)($this->_memoryLimit*2/3);
199 if ($this->_backend !==
null) {
212 $this->_memoryLimit = $newLimit;
224 return $this->_memoryLimit;
234 $this->_minSize = $newSize;
244 return $this->_minSize;
256 return $this->_create(
$value,
false);
269 return $this->_create(
$value,
true);
280 private function _create(
$value, $locked)
282 $id = $this->_nextId++;
284 if ($locked || ($this->_backend ===
null) ) {
294 $this->_sizes[
$id] = 0;
296 $this->_lastModified = $valueObject;
312 if ($this->_lastModified === $container) {
314 $this->_lastModified =
null;
315 unset($this->_sizes[
$id]);
319 if (isset($this->_unloadCandidates[
$id])) {
320 unset($this->_unloadCandidates[
$id]);
323 $this->_memorySize -= $this->_sizes[
$id];
324 unset($this->_sizes[
$id]);
342 if ($container === $this->_lastModified) {
347 if( isset($this->_unloadCandidates[
$id])) {
348 unset($this->_unloadCandidates[
$id]);
352 $this->_memorySize -= $this->_sizes[
$id];
357 $this->_lastModified = $container;
363 private function _commit()
365 if (($container = $this->_lastModified) ===
null) {
369 $this->_lastModified =
null;
371 $id = $container->getId();
374 $this->_memorySize += ($this->_sizes[
$id] = strlen($container->getRef()));
376 if ($this->_sizes[
$id] > $this->_minSize) {
378 $this->_unloadCandidates[
$id] = $container;
381 $container->startTrace();
391 private function _swapCheck()
393 if ($this->_memoryLimit < 0 || $this->_memorySize < $this->_memoryLimit) {
400 foreach ($this->_unloadCandidates as
$id => $container) {
401 $this->_swap($container,
$id);
402 unset($this->_unloadCandidates[
$id]);
404 if ($this->_memorySize < $this->_memoryLimit) {
410 #require_once 'Zend/Memory/Exception.php'; 430 $this->_backend->save($container->
getRef(), $this->_managerId .
$id, $this->_tags);
433 $this->_memorySize -= $this->_sizes[
$id];
448 $value = $this->_backend->load($this->_managerId .
$id,
true);
452 $this->_memorySize += strlen(
$value);
458 if ($this->_sizes[
$id] > $this->_minSize) {
460 $this->_unloadCandidates[
$id] = $container;
load(Zend_Memory_Container_Movable $container, $id)
processUpdate(Zend_Memory_Container_Movable $container, $id)
unlink(Zend_Memory_Container_Movable $container, $id)
setMemoryLimit($newLimit)
const CLEANING_MODE_MATCHING_TAG
__construct($backend=null)