Skip to content

Commit c7b7afc

Browse files
committed
MAGETWO-52836: Enable EAV attributes caching
1 parent 907cc94 commit c7b7afc

File tree

1 file changed

+21
-55
lines changed

1 file changed

+21
-55
lines changed

app/code/Magento/Customer/Model/Metadata/CachedMetadata.php

Lines changed: 21 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,6 @@ class CachedMetadata implements MetadataInterface
3232
*/
3333
protected $metadata;
3434

35-
/**
36-
* @var array
37-
*/
38-
protected $attributeMetadataCache = [];
39-
40-
/**
41-
* @var array
42-
*/
43-
protected $attributesCache = [];
44-
45-
/**
46-
* @var \Magento\Customer\Api\Data\AttributeMetadataInterface[]
47-
*/
48-
protected $allAttributeMetadataCache = null;
49-
50-
/**
51-
* @var \Magento\Customer\Api\Data\AttributeMetadataInterface[]
52-
*/
53-
protected $customAttributesMetadataCache = null;
54-
5535
/**
5636
* Initialize dependencies.
5737
*
@@ -67,69 +47,55 @@ public function __construct(MetadataInterface $metadata)
6747
*/
6848
public function getAttributes($formCode)
6949
{
70-
$key = $formCode;
71-
if (isset($this->attributesCache[$key])) {
72-
return $this->attributesCache[$key];
50+
$attributes = $this->getCache()->getAttributes($this->entityType, $formCode);
51+
if ($attributes !== false) {
52+
return $attributes;
7353
}
74-
75-
$value = $this->metadata->getAttributes($formCode);
76-
$this->attributesCache[$key] = $value;
77-
78-
return $value;
54+
$attributes = $this->metadata->getAttributes($formCode);
55+
$this->getCache()->saveAttributes($this->entityType, $attributes, $formCode);
56+
return $attributes;
7957
}
8058

8159
/**
8260
* {@inheritdoc}
8361
*/
8462
public function getAttributeMetadata($attributeCode)
8563
{
86-
$key = $attributeCode;
87-
if (isset($this->attributeMetadataCache[$key])) {
88-
return $this->attributeMetadataCache[$key];
64+
$metadata = $this->getCache()->getAttributes($this->entityType, $attributeCode);
65+
if ($metadata) {
66+
return $metadata;
8967
}
90-
91-
$value = $this->metadata->getAttributeMetadata($attributeCode);
92-
$this->attributeMetadataCache[$key] = $value;
93-
94-
return $value;
68+
$metadata = $this->metadata->getAttributeMetadata($attributeCode);
69+
$this->getCache()->saveAttributes($this->entityType, $metadata, $attributeCode);
70+
return $metadata;
9571
}
9672

9773
/**
9874
* {@inheritdoc}
9975
*/
10076
public function getAllAttributesMetadata()
10177
{
102-
if ($this->allAttributeMetadataCache !== null) {
103-
return $this->allAttributeMetadataCache;
104-
}
10578
$attributes = $this->getCache()->getAttributes($this->entityType, 'all');
106-
if ($attributes) {
107-
$this->allAttributeMetadataCache = $attributes;
108-
return $this->allAttributeMetadataCache;
79+
if ($attributes !== false) {
80+
return $attributes;
10981
}
110-
111-
112-
$this->allAttributeMetadataCache = $this->metadata->getAllAttributesMetadata();
113-
$this->getCache()->saveAttributes($this->entityType, $this->allAttributeMetadataCache, 'all');
114-
return $this->allAttributeMetadataCache;
82+
$attributes = $this->metadata->getCustomAttributesMetadata();
83+
$this->getCache()->saveAttributes($this->entityType, $attributes, 'all');
84+
return $attributes;
11585
}
11686

11787
/**
11888
* {@inheritdoc}
11989
*/
12090
public function getCustomAttributesMetadata($dataObjectClassName = null)
12191
{
122-
if ($this->customAttributesMetadataCache !== null) {
123-
return $this->customAttributesMetadataCache;
124-
}
12592
$attributes = $this->getCache()->getAttributes($this->entityType, 'custom');
126-
if ($attributes) {
127-
$this->customAttributesMetadataCache = $attributes;
128-
return $this->customAttributesMetadataCache;
93+
if ($attributes !== false) {
94+
return $attributes;
12995
}
130-
$this->customAttributesMetadataCache = $this->metadata->getCustomAttributesMetadata();
96+
$attributes = $this->metadata->getCustomAttributesMetadata();
13197
$this->getCache()->saveAttributes($this->entityType, $attributes, 'custom');
132-
return $this->customAttributesMetadataCache;
98+
return $attributes;
13399
}
134100

135101
/**

0 commit comments

Comments
 (0)