PluginProbe
JCH Optimize / trunk
JCH Optimize vtrunk
6.0.2 6.0.1 trunk 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.10.0 2.2.0 2.2.1 All 58 releases
jch-optimize / src / Platform / Cache.php

Cache.php in JCH Optimize trunk, at src/Platform/Cache.php

117 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * JCH Optimize - Performs several front-end optimizations for fast downloads
5 *
6 * @package jchoptimize/wordpress-platform
7 * @author Samuel Marshall <samuel@jch-optimize.net>
8 * @copyright Copyright (c) 2022 Samuel Marshall / JCH Optimize
9 * @license GNU/GPLv3, or later. See LICENSE file
10 *
11 * If LICENSE file missing, see <http://www.gnu.org/licenses/>.
12 */
13
14 namespace JchOptimize\WordPress\Platform;
15
16 use JchOptimize\Core\Platform\CacheInterface;
17 use JchOptimize\Core\Registry;
18
19 use function get_current_blog_id;
20 use function header;
21 use function is_multisite;
22
23 class Cache implements CacheInterface
24 {
25 public function cleanThirdPartyPageCache(): void
26 {
27 // Not currently used on this platform.
28 }
29
30 public function prepareDataFromCache(?array $data): ?array
31 {
32 return $data;
33 }
34
35 #[NoReturn]
36 public function outputData(array $data): void
37 {
38 /** @psalm-var array{headers:string[], body:string} $data */
39 if (!empty($data['headers'])) {
40 foreach ($data['headers'] as $header) {
41 header($header);
42 }
43 }
44
45 echo $data['body'];
46
47 exit();
48 }
49
50 /**
51 * @param Registry $params
52 *
53 * @return string
54 */
55 public static function getCacheStorage(Registry $params): string
56 {
57 /** @var string */
58 return $params->get('pro_cache_storage_adapter', 'filesystem');
59 }
60
61
62 public function isPageCacheEnabled(Registry $params, bool $nativeCache = false): bool
63 {
64 return (bool)$params->get('cache_enable', '0');
65 }
66
67 /**
68 * @param bool $pageCache
69 *
70 * @return string
71 * @deprecated
72 */
73 public function getCacheNamespace(bool $pageCache = false): string
74 {
75 $id = '';
76
77 if (is_multisite()) {
78 $id = get_current_blog_id();
79 }
80
81 if ($pageCache) {
82 return 'jchoptimizepagecache' . $id;
83 }
84
85 return 'jchoptimizecache' . $id;
86 }
87
88 public function isCaptureCacheIncompatible(): bool
89 {
90 return is_multisite();
91 }
92
93 public function getPageCacheNamespace(): string
94 {
95 return 'jchoptimizepagecache' . $this->getCurrentSiteId();
96 }
97
98 public function getGlobalCacheNamespace(): string
99 {
100 return 'jchoptimizecache' . $this->getCurrentSiteId();
101 }
102
103 public function getTaggableCacheNamespace(): string
104 {
105 return 'jchoptimizetags' . $this->getCurrentSiteId();
106 }
107
108 private function getCurrentSiteId(): string
109 {
110 if (is_multisite()) {
111 return (string) get_current_blog_id();
112 }
113
114 return '';
115 }
116 }
117