PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.1.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.1.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Page_Cache.php

Page_Cache.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.1.0, at src/Performance/Page_Cache.php

151 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * A set of methods that let other developers interact with Solid Performance.
4 *
5 * @since 0.1.0
6 *
7 * @package SolidWP\Performance
8 */
9
10 namespace SolidWP\Performance;
11
12 use SolidWP\Performance\Config\Advanced_Cache;
13 use SolidWP\Performance\Config\Config;
14 use SolidWP\Performance\Config\WP_Config;
15 use SolidWP\Performance\Page_Cache\Purge;
16
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 /**
22 * A set of methods that let other developers interact with Solid Performance.
23 *
24 * @since 0.1.0
25 *
26 * @package SolidWP\Performance
27 */
28 class Page_Cache {
29
30 /**
31 * @var Config
32 */
33 private Config $config;
34
35 /**
36 * @var WP_Config
37 */
38 private WP_Config $wp_config;
39
40 /**
41 * @var Purge
42 */
43 private Purge $purge;
44
45 /**
46 * @var Advanced_Cache
47 */
48 private Advanced_Cache $advanced_cache;
49
50 /**
51 * @param Config $config The config class.
52 * @param WP_Config $wp_config The wp config class.
53 * @param Purge $purge The cache purger.
54 * @param Advanced_Cache $advanced_cache The advanced cache?.
55 */
56 public function __construct(
57 Config $config,
58 WP_Config $wp_config,
59 Purge $purge,
60 Advanced_Cache $advanced_cache
61 ) {
62 $this->config = $config;
63 $this->wp_config = $wp_config;
64 $this->purge = $purge;
65 $this->advanced_cache = $advanced_cache;
66 }
67
68 /**
69 * Enables the page cache.
70 *
71 * @since 0.1.0
72 *
73 * @return bool true on success, false on failure
74 */
75 public function on(): bool {
76 return $this->wp_config->set_wp_cache( 'true' );
77 }
78
79 /**
80 * Enables the page cache.
81 *
82 * @since 0.1.0
83 *
84 * @return bool true on success, false on failure
85 */
86 public function off(): bool {
87 return $this->wp_config->set_wp_cache( 'false' );
88 }
89
90 /**
91 * Checks if the page cache is currently enabled.
92 *
93 * @since 0.1.0
94 *
95 * @return bool true when enabled, false when disabled.
96 */
97 public function is_on(): bool {
98 return $this->wp_config->get_wp_cache_status();
99 }
100
101 /**
102 * Clears all pages from the page cache.
103 *
104 * @since 0.1.0
105 *
106 * @return bool
107 */
108 public function clear(): bool {
109 return $this->purge->all_pages();
110 }
111
112 /**
113 * Regenerates the advanced-cache.php file.
114 *
115 * @since 0.1.0
116 *
117 * @return bool
118 */
119 public function regenerate_advanced_cache(): bool {
120 return $this->advanced_cache->generate();
121 }
122
123 /**
124 * Gets the current status of debug mode.
125 *
126 * @since 0.1.0
127 *
128 * @return bool
129 */
130 public function is_debug_on(): bool {
131 return $this->config->get( 'page_cache.debug' );
132 }
133
134 /**
135 * Sets the state of debug mode.
136 *
137 * @since 0.1.0
138 *
139 * @param bool $state The state for debug mode.
140 *
141 * @return bool
142 */
143 public function debug( bool $state ): bool {
144 $config = $this->config;
145 $config->set( 'page_cache.debug', $state );
146 $config->save();
147
148 return (bool) $config->get( 'page_cache.debug' );
149 }
150 }
151