File tree Expand file tree Collapse file tree 5 files changed +138
-1
lines changed
Expand file tree Collapse file tree 5 files changed +138
-1
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Firegento \CacheWarmup \Api ;
5+
6+ interface CacheVaryDataRepositoryInterface
7+ {
8+ /**
9+ * @param array $varyData
10+ */
11+ public function save (array $ varyData ): void ;
12+
13+ /**
14+ * @return array[]
15+ */
16+ public function getAll (): array ;
17+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Firegento \CacheWarmup \Model ;
5+
6+ use Firegento \CacheWarmup \Api \CacheVaryDataRepositoryInterface ;
7+ use Firegento \CacheWarmup \Model \VaryData \Query \GetAllVaryData ;
8+ use Firegento \CacheWarmup \Model \VaryData \Query \SaveVaryData ;
9+
10+ class CacheVaryDataRepository implements CacheVaryDataRepositoryInterface
11+ {
12+ /**
13+ * @var SaveVaryData
14+ */
15+ private $ saveVaryData ;
16+ /**
17+ * @var GetAllVaryData
18+ */
19+ private $ getAllVaryData ;
20+
21+ public function __construct (SaveVaryData $ saveVaryData , GetAllVaryData $ getAllVaryData )
22+ {
23+ $ this ->saveVaryData = $ saveVaryData ;
24+ $ this ->getAllVaryData = $ getAllVaryData ;
25+ }
26+
27+ /**
28+ * @param array $varyData
29+ */
30+ public function save (array $ varyData ): void
31+ {
32+ $ this ->saveVaryData ->execute ($ varyData );
33+ }
34+
35+ /**
36+ * @return array[]
37+ */
38+ public function getAll (): array
39+ {
40+ return $ this ->getAllVaryData ->execute ();
41+ }
42+ }
Original file line number Diff line number Diff line change @@ -26,4 +26,4 @@ public function execute(CacheTagInterface $cacheTag): void
2626 ['cache_tag ' => $ cacheTag ->getCacheTag ()]
2727 );
2828 }
29- }
29+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+ /**
4+ * GetAllVaryData
5+ *
6+ * @copyright Copyright © 2019 brandung GmbH & Co. KG. All rights reserved.
7+ * @author david.verholen@brandung.de
8+ */
9+
10+ namespace Firegento \CacheWarmup \Model \VaryData \Query ;
11+
12+ use Magento \Framework \App \ResourceConnection ;
13+ use Magento \Framework \Serialize \SerializerInterface ;
14+
15+ class GetAllVaryData
16+ {
17+ /**
18+ * @var ResourceConnection
19+ */
20+ protected $ resourceConnection ;
21+ /**
22+ * @var SerializerInterface
23+ */
24+ private $ serializer ;
25+
26+ public function __construct (ResourceConnection $ resourceConnection , SerializerInterface $ serializer )
27+ {
28+ $ this ->resourceConnection = $ resourceConnection ;
29+ $ this ->serializer = $ serializer ;
30+ }
31+
32+ /**
33+ * @return array[]
34+ */
35+ public function execute (): array
36+ {
37+ $ connection = $ this ->resourceConnection ->getConnection ();
38+ return $ connection ->select ()
39+ ->from ('cache_vary_data ' )
40+ ->query ()
41+ ->fetchAll ();
42+ }
43+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Firegento \CacheWarmup \Model \VaryData \Query ;
5+
6+ use Magento \Framework \App \ResourceConnection ;
7+ use Magento \Framework \Serialize \SerializerInterface ;
8+
9+ class SaveVaryData
10+ {
11+ /**
12+ * @var ResourceConnection
13+ */
14+ protected $ resourceConnection ;
15+ /**
16+ * @var SerializerInterface
17+ */
18+ private $ serializer ;
19+
20+ public function __construct (ResourceConnection $ resourceConnection , SerializerInterface $ serializer )
21+ {
22+ $ this ->resourceConnection = $ resourceConnection ;
23+ $ this ->serializer = $ serializer ;
24+ }
25+
26+ public function execute (array $ varyData ): void
27+ {
28+ $ connection = $ this ->resourceConnection ->getConnection ();
29+ $ connection ->insertOnDuplicate (
30+ 'cache_vary_data ' ,
31+ ['vary_data ' => $ this ->serializer ->serialize ($ varyData )],
32+ ['vary_data ' ]
33+ );
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments