Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PageCachePlugin.php
Go to the documentation of this file.
1 <?php
2 /***
3  * Copyright © Magento, Inc. All rights reserved.
4  * See COPYING.txt for license details.
5  */
6 
8 
10 {
14  const COMPRESSION_PREFIX = 'COMPRESSED_CACHE_';
15 
28  public function beforeSave(
29  \Magento\Framework\App\PageCache\Cache $subject,
30  $data,
31  $identifier,
32  $tags = [],
33  $lifeTime = null
34  ) {
35  $data = $this->handleCompression($data);
37  return [$data, $identifier, $tags, $lifeTime];
38  }
39 
50  public function afterLoad(
51  \Magento\Framework\App\PageCache\Cache $subject,
52  $result
53  ) {
54  if ($result && strpos($result, self::COMPRESSION_PREFIX) === 0) {
55  $result = function_exists('gzuncompress')
56  ? gzuncompress(substr($result, strlen(self::COMPRESSION_PREFIX)))
57  : false;
58  }
59  return $result;
60  }
61 
68  private function handleCompression($data)
69  {
70  if (function_exists('gzcompress')) {
71  $data = self::COMPRESSION_PREFIX . gzcompress($data);
72  }
73  return $data;
74  }
75 }
beforeSave(\Magento\Framework\App\PageCache\Cache $subject, $data, $identifier, $tags=[], $lifeTime=null)
afterLoad(\Magento\Framework\App\PageCache\Cache $subject, $result)