11
11
*/
12
12
namespace Magento \Eav \Model \Entity \Attribute \Frontend ;
13
13
14
+ use Magento \Framework \App \CacheInterface ;
15
+ use Magento \Store \Api \StoreResolverInterface ;
16
+ use Magento \Framework \App \ObjectManager ;
17
+ use Magento \Eav \Model \Cache \Type as CacheType ;
18
+ use Magento \Eav \Model \Entity \Attribute ;
19
+
14
20
abstract class AbstractFrontend implements \Magento \Eav \Model \Entity \Attribute \Frontend \FrontendInterface
15
21
{
22
+ /**
23
+ * @var CacheInterface
24
+ */
25
+ private $ cache ;
26
+
27
+ /**
28
+ * @var StoreResolverInterface
29
+ */
30
+ private $ storeResolver ;
31
+
32
+ /**
33
+ * @var array
34
+ */
35
+ private $ cacheTags ;
36
+
16
37
/**
17
38
* Reference to the attribute instance
18
39
*
@@ -27,11 +48,24 @@ abstract class AbstractFrontend implements \Magento\Eav\Model\Entity\Attribute\F
27
48
28
49
/**
29
50
* @param \Magento\Eav\Model\Entity\Attribute\Source\BooleanFactory $attrBooleanFactory
51
+ * @param CacheInterface $cache
52
+ * @param StoreResolverInterface $storeResolver
53
+ * @param array $cacheTags
30
54
* @codeCoverageIgnore
31
55
*/
32
- public function __construct (\Magento \Eav \Model \Entity \Attribute \Source \BooleanFactory $ attrBooleanFactory )
33
- {
56
+ public function __construct (
57
+ \Magento \Eav \Model \Entity \Attribute \Source \BooleanFactory $ attrBooleanFactory ,
58
+ CacheInterface $ cache = null ,
59
+ StoreResolverInterface $ storeResolver = null ,
60
+ array $ cacheTags = [
61
+ CacheType::CACHE_TAG ,
62
+ Attribute::CACHE_TAG ,
63
+ ]
64
+ ) {
34
65
$ this ->_attrBooleanFactory = $ attrBooleanFactory ;
66
+ $ this ->cache = $ cache ?: ObjectManager::getInstance ()->get (CacheInterface::class);
67
+ $ this ->storeResolver = $ storeResolver ?: ObjectManager::getInstance ()->get (StoreResolverInterface::class);
68
+ $ this ->cacheTags = $ cacheTags ;
35
69
}
36
70
37
71
/**
@@ -216,7 +250,21 @@ public function getConfigField($fieldName)
216
250
*/
217
251
public function getSelectOptions ()
218
252
{
219
- return $ this ->getAttribute ()->getSource ()->getAllOptions ();
253
+ $ cacheKey = 'attribute-navigation-option- ' .
254
+ $ this ->getAttribute ()->getAttributeCode () . '- ' .
255
+ $ this ->storeResolver ->getCurrentStoreId ();
256
+ $ optionString = $ this ->cache ->load ($ cacheKey );
257
+ if (false === $ optionString ) {
258
+ $ options = $ this ->getAttribute ()->getSource ()->getAllOptions ();
259
+ $ this ->cache ->save (
260
+ json_encode ($ options ),
261
+ $ cacheKey ,
262
+ $ this ->cacheTags
263
+ );
264
+ } else {
265
+ $ options = json_decode ($ optionString , true );
266
+ }
267
+ return $ options ;
220
268
}
221
269
222
270
/**
0 commit comments