Skip to content

Commit 61bab7b

Browse files
committed
ACPT-867: STRUCTURE LAYOUT cache generates for each product category and takes ~18Kb (GZIP) per ea.
1 parent 1819863 commit 61bab7b

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

lib/internal/Magento/Framework/App/Cache/Type/Layout.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
*/
1111
class Layout extends \Magento\Framework\Cache\Frontend\Decorator\TagScope
1212
{
13+
/**
14+
* Prefix for hash kay and hash data
15+
*/
16+
private const HASH_PREFIX = 'l:';
17+
18+
/**
19+
* Hash type
20+
*/
21+
private const HASH_TYPE = 'xxh3';
22+
23+
private const DATA_LIFETIME = 86_400_000; // "1 day" miliseconds
1324
/**
1425
* Cache type code unique among all cache types
1526
*/
@@ -27,4 +38,34 @@ public function __construct(FrontendPool $cacheFrontendPool)
2738
{
2839
parent::__construct($cacheFrontendPool->get(self::TYPE_IDENTIFIER), self::CACHE_TAG);
2940
}
41+
42+
/**
43+
* @inheritDoc
44+
*/
45+
public function save($data, $identifier, array $tags = [], $lifeTime = null)
46+
{
47+
$dataHash = hash(self::HASH_TYPE, $data);
48+
$identifierForHash = self::HASH_PREFIX . $dataHash;
49+
return parent::save($data, $identifierForHash, $tags, self::DATA_LIFETIME) // key is hash of data hash
50+
&& parent::save(self::HASH_PREFIX . $dataHash, $identifier, $tags, $lifeTime); // store hash of data
51+
52+
}
53+
54+
/**
55+
* @inheritDoc
56+
*/
57+
public function load($identifier)
58+
{
59+
$data = parent::load($identifier);
60+
if ($data === false) {
61+
return $data;
62+
}
63+
64+
if (str_starts_with($data, self::HASH_PREFIX)) {
65+
// so data stored in other place
66+
return parent::load($data);
67+
} else {
68+
return $data;
69+
}
70+
}
3071
}

lib/internal/Magento/Framework/Cache/Backend/Redis.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function load($id, $doNotTestCacheValidity = false)
7070
* @param bool $specificLifetime
7171
* @return bool
7272
*/
73-
public function save($data, $id, $tags = [], $specificLifetime = false)
73+
public function save($data, $id, $tags = [], $specificLifetime = 86_400_000)
7474
{
7575
// @todo add special handling of MAGE tag, save clenup
7676
try {

0 commit comments

Comments
 (0)