Object Cache
Stores objects for reuse, cleanup and to avoid circular references
- Author
- Magento Core Team core@.nosp@m.mage.nosp@m.ntoco.nosp@m.mmer.nosp@m.ce.co.nosp@m.m
Definition at line 15 of file Cache.php.
◆ debug()
debug |
( |
|
$idx, |
|
|
|
$object = null |
|
) |
| |
Debug
- Parameters
-
string | $idx | |
object | null | $object | |
- Returns
- void @SuppressWarnings(PHPMD.UnusedFormalParameter)
Definition at line 395 of file Cache.php.
397 $bt = debug_backtrace();
399 foreach ($bt as
$i => $step) {
401 'file' => isset($step[
'file']) ? $step[
'file'] :
null,
402 'line' => isset($step[
'line']) ? $step[
'line'] :
null,
403 'function' => isset($step[
'function']) ? $step[
'function'] :
null,
406 $this->_debug[$idx] =
$debug;
◆ debugByIds()
Return debug information by ids
- Parameters
-
- Returns
- array
Definition at line 415 of file Cache.php.
417 if (is_string($ids)) {
421 foreach ($ids as $idx) {
422 $debug[$idx] = $this->_debug[$idx];
◆ delete()
Delete an object from registry
- Parameters
-
- Returns
- boolean
Definition at line 217 of file Cache.php.
220 if (is_object($idx)) {
221 $idx = $this->
find($idx);
222 if (
false === $idx) {
226 unset($this->_objects[$idx]);
229 }
elseif (!isset($this->_objects[$idx])) {
234 unset($this->_objects[$idx]);
236 unset($this->_hashes[$this->_objectHashes[$idx]], $this->_objectHashes[$idx]);
238 if (isset($this->_objectTags[$idx])) {
239 foreach ($this->_objectTags[$idx] as $t => $dummy) {
240 unset($this->_tags[$t][$idx]);
242 unset($this->_objectTags[$idx]);
245 if (isset($this->_objectReferences[$idx])) {
246 foreach ($this->_references as $r => $dummy) {
247 unset($this->_references[$r]);
249 unset($this->_objectReferences[$idx]);
elseif(isset( $params[ 'redirect_parent']))
◆ deleteByClass()
Cleanup by class name for objects of subclasses too
- Parameters
-
- Returns
- void
Definition at line 262 of file Cache.php.
264 foreach ($this->_objects as $idx => $object) {
265 if ($object instanceof
$class) {
$_option $_optionId $class
◆ deleteByTags()
Cleanup objects by tags
- Parameters
-
- Returns
- true @SuppressWarnings(PHPMD.UnusedLocalVariable)
Definition at line 278 of file Cache.php.
280 if (is_string($tags)) {
283 foreach ($tags as $t) {
284 foreach ($this->_tags[$t] as $idx => $dummy) {
◆ find()
Find an object id
- Parameters
-
- Returns
- string|boolean
Definition at line 308 of file Cache.php.
310 foreach ($this->_objects as $idx => $obj) {
311 if ($object === $obj) {
◆ findByClass()
Find by class name for objects of subclasses too
- Parameters
-
- Returns
- array
Definition at line 376 of file Cache.php.
379 foreach ($this->_objects as $idx => $object) {
380 if ($object instanceof
$class) {
381 $objects[$idx] = $object;
$_option $_optionId $class
◆ findByHash()
Find object by hash
- Parameters
-
- Returns
- object
Definition at line 341 of file Cache.php.
343 return isset($this->_hashes[$hash]) ? $this->_objects[$this->_hashes[$hash]] :
null;
◆ findByIds()
Find objects by ids
- Parameters
-
- Returns
- array
Definition at line 324 of file Cache.php.
327 foreach ($this->_objects as $idx => $obj) {
328 if (in_array($idx, $ids)) {
329 $objects[$idx] = $obj;
◆ findByTags()
Find objects by tags
- Parameters
-
- Returns
- array @SuppressWarnings(PHPMD.UnusedLocalVariable)
Definition at line 353 of file Cache.php.
355 if (is_string($tags)) {
359 foreach ($tags as $t) {
360 foreach ($this->_tags[$t] as $idx => $dummy) {
361 if (isset($objects[$idx])) {
364 $objects[$idx] = $this->
load($idx);
load($idx, $default=null)
◆ getAllObjects()
Get all objects
- Returns
- array
Definition at line 432 of file Cache.php.
◆ getAllReferences()
Get all references
- Returns
- array
Definition at line 462 of file Cache.php.
◆ getAllTags()
Get all tags
- Returns
- array
Definition at line 442 of file Cache.php.
◆ getAllTagsByObject()
Get all tags by object
- Returns
- array
Definition at line 452 of file Cache.php.
◆ has()
Check whether object id exists in registry
- Parameters
-
- Returns
- boolean
Definition at line 297 of file Cache.php.
299 return isset($this->_objects[$idx]) || isset($this->_references[$idx]);
◆ load()
load |
( |
|
$idx, |
|
|
|
$default = null |
|
) |
| |
Load an object from registry
- Parameters
-
string | object | $idx | |
object | $default | |
- Returns
- object
Definition at line 107 of file Cache.php.
109 if (isset($this->_references[$idx])) {
110 $idx = $this->_references[$idx];
112 if (isset($this->_objects[$idx])) {
113 return $this->_objects[$idx];
◆ reference()
reference |
( |
|
$refName, |
|
|
|
$idx |
|
) |
| |
Add a reference to an object
- Parameters
-
string | array | $refName | |
string | $idx | |
- Returns
- bool|void
- Exceptions
-
Definition at line 188 of file Cache.php.
190 if (is_array($refName)) {
191 foreach ($refName as $ref) {
197 if (isset($this->_references[$refName])) {
198 throw new \Magento\Framework\Exception\LocalizedException(
200 'The reference already exists: %1. New index: %2, old index: %3',
201 [$refName, $idx, $this->_references[$refName]]
205 $this->_references[$refName] = $idx;
206 $this->_objectReferences[$idx][$refName] =
true;
reference($refName, $idx)
◆ save()
save |
( |
|
$object, |
|
|
|
$idx = null , |
|
|
|
$tags = null |
|
) |
| |
Save an object entry
- Parameters
-
object | $object | |
string | $idx | |
array | string | $tags | |
- Returns
- string
- Exceptions
-
Definition at line 129 of file Cache.php.
132 if (!is_object($object)) {
136 $hash = spl_object_hash($object);
137 if ($idx !==
null && strpos($idx,
'{') !==
false) {
138 $idx = str_replace(
'{hash}', $hash, $idx);
140 if (isset($this->_hashes[$hash])) {
143 $this->_references[$idx] = $this->_hashes[$hash];
145 return $this->_hashes[$hash];
152 if (isset($this->_objects[$idx])) {
153 throw new \Magento\Framework\Exception\LocalizedException(
155 'Object already exists in registry (%1). Old object class: %2, new object class: %3',
156 [$idx, get_class($this->_objects[$idx]), get_class($object)]
161 $this->_objects[$idx] = $object;
163 $this->_hashes[$hash] = $idx;
164 $this->_objectHashes[$idx] = $hash;
166 if (is_string($tags)) {
167 $this->_tags[$tags][$idx] =
true;
168 $this->_objectTags[$idx][$tags] =
true;
169 }
elseif (is_array($tags)) {
170 foreach ($tags as $t) {
171 $this->_tags[$t][$idx] =
true;
172 $this->_objectTags[$idx][$t] =
true;
elseif(isset( $params[ 'redirect_parent']))
◆ singleton()
Singleton factory
- Returns
- \Magento\Framework\DataObject\Cache
Definition at line 92 of file Cache.php.
94 if (!self::$_instance) {
95 self::$_instance =
new self();
◆ $_debug
◆ $_hashes
◆ $_idx
◆ $_instance
◆ $_objectHashes
◆ $_objectReferences
◆ $_objects
◆ $_objectTags
◆ $_references
◆ $_tags
The documentation for this class was generated from the following file:
- vendor/magento/framework/DataObject/Cache.php