11
11
12
12
namespace Magepow \Categories \Block ;
13
13
14
- class Categories extends \Magento \Framework \View \Element \Template
14
+ class Categories extends \Magento \Framework \View \Element \Template implements \ Magento \ Framework \ DataObject \IdentityInterface
15
15
{
16
+ const DEFAULT_CACHE_TAG = 'MAGEPOW_CATEGORIES ' ;
17
+
16
18
const XML_PATH = 'category_page ' ;
17
19
18
20
public $ helper ;
@@ -46,6 +48,28 @@ public function __construct(
46
48
parent ::__construct ($ context , $ data );
47
49
}
48
50
51
+ protected function getCacheLifetime ()
52
+ {
53
+ return parent ::getCacheLifetime () ?: 86400 ;
54
+ }
55
+
56
+ public function getCacheKeyInfo ()
57
+ {
58
+ $ keyInfo = parent ::getCacheKeyInfo ();
59
+ $ categoryId = $ this ->getCurrentCategory () ? $ this ->getCurrentCategory ()->getId () : 0 ;
60
+ $ keyInfo [] = $ categoryId ;
61
+ return $ keyInfo ;
62
+ }
63
+
64
+ /**
65
+ * @return array
66
+ */
67
+ public function getIdentities ()
68
+ {
69
+ $ categoryId = $ this ->getCurrentCategory () ? $ this ->getCurrentCategory ()->getId () : 0 ;
70
+ return [self ::DEFAULT_CACHE_TAG , self ::DEFAULT_CACHE_TAG . '_ ' . $ categoryId ];
71
+ }
72
+
49
73
public function getLayout ()
50
74
{
51
75
return $ this ->helper ->getConfig (self ::XML_PATH . '/layout ' );
@@ -71,10 +95,15 @@ public function getExcludeCategory()
71
95
return $ this ->helper ->getConfig (self ::XML_PATH . '/exclude_category ' );
72
96
}
73
97
98
+ public function getCurrentCategory ()
99
+ {
100
+ return $ this ->coreRegistry ->registry ('current_category ' );
101
+ }
102
+
74
103
public function getCategories ()
75
104
{
76
105
77
- $ category = $ this ->coreRegistry -> registry ( ' current_category ' );
106
+ $ category = $ this ->getCurrentCategory ( );
78
107
if (!$ category ) return ;
79
108
80
109
$ categoryId = $ category ->getId ();
0 commit comments