Public Member Functions | |
load ($idx, $default=null) | |
save ($object, $idx=null, $tags=null) | |
reference ($refName, $idx) | |
delete ($idx) | |
deleteByClass ($class) | |
deleteByTags ($tags) | |
has ($idx) | |
find ($object) | |
findByIds ($ids) | |
findByHash ($hash) | |
findByTags ($tags) | |
findByClass ($class) | |
debug ($idx, $object=null) | |
debugByIds ($ids) | |
getAllObjects () | |
getAllTags () | |
getAllTagsByObject () | |
getAllReferences () | |
getAllReferencesByObject () | |
Static Public Member Functions | |
static | singleton () |
Protected Attributes | |
$_idx = 0 | |
$_objects = array() | |
$_hashes = array() | |
$_objectHashes = array() | |
$_tags = array() | |
$_objectTags = array() | |
$_references = array() | |
$_objectReferences = array() | |
$_debug = array() | |
Static Protected Attributes | |
static | $_instance |
Stores objects for reuse, cleanup and to avoid circular references
Definition at line 35 of file Cache.php.
debug | ( | $ | idx, | |
$ | object = null | |||
) |
Definition at line 376 of file Cache.php.
00377 { 00378 $bt = debug_backtrace(); 00379 $debug = array(); 00380 foreach ($bt as $i=>$step) { 00381 $debug[$i] = array( 00382 'file' => isset($step['file']) ? $step['file'] : null, 00383 'line' => isset($step['line']) ? $step['line'] : null, 00384 'function' => isset($step['function']) ? $step['function'] : null, 00385 ); 00386 } 00387 $this->_debug[$idx] = $debug; 00388 }
debugByIds | ( | $ | ids | ) |
Return debug information by ids
array|integer | $ids |
Definition at line 396 of file Cache.php.
00397 { 00398 if (is_string($ids)) { 00399 $ids = array($ids); 00400 } 00401 $debug = array(); 00402 foreach ($ids as $idx) { 00403 $debug[$idx] = $this->_debug[$idx]; 00404 } 00405 return $debug; 00406 }
delete | ( | $ | idx | ) |
Delete an object from registry
string|object | $idx |
Definition at line 223 of file Cache.php.
00224 { 00225 //Varien_Profiler::start("OBJECT_DELETE"); 00226 if (is_object($idx)) { 00227 $idx = $this->find($idx); 00228 if (false===$idx) { 00229 //Varien_Profiler::stop("OBJECT_DELETE"); 00230 return false; 00231 } 00232 unset($this->_objects[$idx]); 00233 //Varien_Profiler::stop("OBJECT_DELETE"); 00234 return false; 00235 } elseif (!isset($this->_objects[$idx])) { 00236 //Varien_Profiler::stop("OBJECT_DELETE"); 00237 return false; 00238 } 00239 00240 unset($this->_objects[$idx]); 00241 00242 unset($this->_hashes[$this->_objectHashes[$idx]], $this->_objectHashes[$idx]); 00243 00244 if (isset($this->_objectTags[$idx])) { 00245 foreach ($this->_objectTags[$idx] as $t=>$dummy) { 00246 unset($this->_tags[$t][$idx]); 00247 } 00248 unset($this->_objectTags[$idx]); 00249 } 00250 00251 if (isset($this->_objectReferences[$idx])) { 00252 foreach ($references as $r=>$dummy) { 00253 unset($this->_references[$r]); 00254 } 00255 unset($this->_objectReferences[$idx]); 00256 } 00257 //Varien_Profiler::stop("OBJECT_DELETE"); 00258 00259 return true; 00260 }
deleteByClass | ( | $ | class | ) |
deleteByTags | ( | $ | tags | ) |
Cleanup objects by tags
array|string | $tags |
Definition at line 281 of file Cache.php.
00282 { 00283 if (is_string($tags)) { 00284 $tags = array($tags); 00285 } 00286 foreach ($tags as $t) { 00287 foreach ($this->_tags[$t] as $idx=>$dummy) { 00288 $this->delete($idx); 00289 } 00290 } 00291 return true; 00292 }
find | ( | $ | object | ) |
findByClass | ( | $ | class | ) |
Find by class name for objects of subclasses too
string | $class |
Definition at line 365 of file Cache.php.
00366 { 00367 $objects = array(); 00368 foreach ($this->_objects as $idx=>$object) { 00369 if ($object instanceof $class) { 00370 $objects[$idx] = $object; 00371 } 00372 } 00373 return $objects; 00374 }
findByHash | ( | $ | hash | ) |
findByIds | ( | $ | ids | ) |
findByTags | ( | $ | tags | ) |
Find objects by tags
array|string | $tags |
Definition at line 343 of file Cache.php.
00344 { 00345 if (is_string($tags)) { 00346 $tags = array($tags); 00347 } 00348 $objects = array(); 00349 foreach ($tags as $t) { 00350 foreach ($this->_tags[$t] as $idx=>$dummy) { 00351 if (isset($objects[$idx])) { 00352 continue; 00353 } 00354 $objects[$ids] = $this->load($idx); 00355 } 00356 } 00357 return $objects; 00358 }
getAllObjects | ( | ) |
getAllReferences | ( | ) |
getAllReferencesByObject | ( | ) |
getAllTags | ( | ) |
getAllTagsByObject | ( | ) |
has | ( | $ | idx | ) |
load | ( | $ | idx, | |
$ | default = null | |||
) |
Load an object from registry
string|object | $idx | |
object | $default |
Definition at line 127 of file Cache.php.
00128 { 00129 if (isset($this->_references[$idx])) { 00130 $idx = $this->_references[$idx]; 00131 } 00132 if (isset($this->_objects[$idx])) { 00133 return $this->_objects[$idx]; 00134 } 00135 return $default; 00136 }
reference | ( | $ | refName, | |
$ | idx | |||
) |
Add a reference to an object
string|array | $refName | |
string | $idx |
Definition at line 199 of file Cache.php.
00200 { 00201 if (is_array($refName)) { 00202 foreach ($refName as $ref) { 00203 $this->reference($ref, $idx); 00204 } 00205 return; 00206 } 00207 00208 if (isset($this->_references[$refName])) { 00209 throw new Varien_Exception('The reference already exists: '.$refName.'. New index: '.$idx.', old index: '.$this->_references[$refName]); 00210 } 00211 $this->_references[$refName] = $idx; 00212 $this->_objectReferences[$idx][$refName] = true; 00213 00214 return true; 00215 }
save | ( | $ | object, | |
$ | idx = null , |
|||
$ | tags = null | |||
) |
Save an object entry
object | $object | |
string | $idx | |
array|string | $tags |
Definition at line 146 of file Cache.php.
00147 { 00148 //Varien_Profiler::start('OBJECT_SAVE'); 00149 if (!is_object($object)) { 00150 return false; 00151 } 00152 00153 $hash = spl_object_hash($object); 00154 if (!is_null($idx) && strpos($idx, '{')) { 00155 $idx = str_replace('{hash}', $hash, $idx); 00156 } 00157 if (isset($this->_hashes[$hash])) { 00158 //throw new Exception('test'); 00159 if (!is_null($idx)) { 00160 $this->_references[$idx] = $this->_hashes[$hash]; 00161 } 00162 return $this->_hashes[$hash]; 00163 } 00164 00165 if (is_null($idx)) { 00166 $idx = '#'.(++$this->_idx); 00167 } 00168 00169 if (isset($this->_objects[$idx])) { 00170 throw new Varien_Exception('Object already exists in registry ('.$idx.'). Old object class: '.get_class($this->_objects[$idx]).', new object class: '.get_class($object)); 00171 } 00172 00173 $this->_objects[$idx] = $object; 00174 00175 $this->_hashes[$hash] = $idx; 00176 $this->_objectHashes[$idx] = $hash; 00177 00178 if (is_string($tags)) { 00179 $this->_tags[$tags][$idx] = true; 00180 $this->_objectTags[$idx][$tags] = true; 00181 } elseif (is_array($tags)) { 00182 foreach ($tags as $t) { 00183 $this->_tags[$t][$idx] = true; 00184 $this->_objectTags[$idx][$t] = true; 00185 } 00186 } 00187 //Varien_Profiler::stop('OBJECT_SAVE'); 00188 00189 return $idx; 00190 }
static singleton | ( | ) | [static] |
Singleton factory
Definition at line 112 of file Cache.php.
00113 { 00114 if (!self::$_instance) { 00115 self::$_instance = new self(); 00116 } 00117 return self::$_instance; 00118 }