PluginProbe
Docket Cache – Object Cache Accelerator / 22.07.01
Docket Cache – Object Cache Accelerator v22.07.01
26.04.05 trunk 22.07.01 22.07.02 22.07.03 22.07.04 22.07.05 23.08.01 23.08.02 24.07.01 24.07.02 24.07.03 24.07.04 24.07.05 24.07.06 24.07.07 26.04.03 26.04.04
docket-cache / includes / object-cache.php

object-cache.php in Docket Cache – Object Cache Accelerator 22.07.01, at includes/object-cache.php

184 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @wordpress-plugin
4 * Plugin Name: Docket Cache Drop-in
5 * Plugin URI: https://wordpress.org/plugins/docket-cache/
6 * Version: 22.07.01
7 * Description: A persistent object cache stored as a plain PHP code, accelerates caching with OPcache backend.
8 * Author: Nawawi Jamili
9 * Author URI: https://docketcache.com
10 * Requires at least: 5.4
11 * Requires PHP: 7.2.5
12 * License: MIT
13 * License URI: https://github.com/nawawi/docket-cache/blob/master/LICENSE.txt
14 */
15 if (!\defined('ABSPATH')) {
16 return;
17 }
18
19 /*
20 * Bypass if caching is disabled.
21 */
22 if (\defined('DOCKET_CACHE_DISABLED') && DOCKET_CACHE_DISABLED) {
23 return;
24 }
25
26 /*
27 * Check for minimum php version.
28 */
29 if (version_compare(\PHP_VERSION, '7.2.5', '<')) {
30 return;
31 }
32
33 /*
34 * Bypass if we doing action.
35 */
36 if (!empty($_GET['_wpnonce']) && !empty($_GET['action']) && !empty($_GET['page']) && 'docket-cache' === $_GET['page'] && false === strpos($_GET['action'], 'cronbot') && false === strpos($_GET['action'], 'wpoptaload')) {
37 return;
38 }
39
40 /*
41 * Bypass if match cache key in $_REQUEST.
42 */
43 if (\defined('DOCKET_CACHE_IGNORE_REQUEST') && \is_array(DOCKET_CACHE_IGNORE_REQUEST) && !empty($_REQUEST)) {
44 if (array_intersect(DOCKET_CACHE_IGNORE_REQUEST, array_keys($_REQUEST))) {
45 return;
46 }
47 }
48
49 /*
50 * Determine if WP_CONTENT_DIR is exists.
51 */
52 if (!\defined('WP_CONTENT_DIR')) {
53 \define('WP_CONTENT_DIR', ABSPATH.'wp-content');
54 }
55
56 /*
57 * Determine if WP_PLUGIN_DIR is exists.
58 */
59 if (!\defined('WP_PLUGIN_DIR')) {
60 \define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins');
61 }
62
63 /*
64 * Determine if DOCKET_CACHE_CONTENT_PATH is exists.
65 */
66 if (!\defined('DOCKET_CACHE_CONTENT_PATH')) {
67 \define('DOCKET_CACHE_CONTENT_PATH', WP_CONTENT_DIR);
68 }
69
70 /*
71 * Determine if docket object cache class and functions exists.
72 */
73 if (!@is_file(WP_PLUGIN_DIR.'/docket-cache/includes/cache.php')) {
74 return;
75 }
76
77 /*
78 * Determine if docket cache autoload exists.
79 */
80 if (!@is_file(WP_PLUGIN_DIR.'/docket-cache/includes/load.php')) {
81 return;
82 }
83
84 /*
85 * Determine if we can load docket cache library.
86 */
87 @include_once WP_PLUGIN_DIR.'/docket-cache/includes/load.php';
88 if (!class_exists('Nawawi\\DocketCache\\Plugin') || !class_exists('Nawawi\\DocketCache\\Constans') || !class_exists('Nawawi\\DocketCache\\Filesystem') || !\function_exists('nwdcx_constfx')) {
89 return;
90 }
91
92 /*
93 * Check if doing flush.
94 */
95 if (@is_file(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-flush.txt')) {
96 if (time() > @filemtime(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-flush.txt')) {
97 @unlink(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-flush.txt');
98 }
99
100 return;
101 }
102
103 /*
104 * Determine if we're on multinetwork and has object cache locking.
105 */
106 if (\function_exists('nwdcx_network_ignore') && nwdcx_network_ignore()) {
107 return;
108 }
109
110 /*
111 * Check for object-cache-delay.txt file.
112 */
113 if (@is_file(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt')) {
114 if (!\function_exists('add_action')) {
115 return;
116 }
117
118 if (time() > @filemtime(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt')) {
119 if (!\function_exists('nwdcx_halttransient')) {
120 // prevent from transient save to db before replace with our dropin
121 function nwdcx_halttransient($value, $option, $old_value = '')
122 {
123 if (false !== strpos($option, '_transient_')) {
124 return false;
125 }
126
127 return $value;
128 }
129
130 add_filter('pre_update_option', 'nwdcx_halttransient', \PHP_INT_MIN, 3);
131 add_filter('pre_get_option', 'nwdcx_halttransient', \PHP_INT_MIN, 3);
132 add_filter(
133 'added_option',
134 function ($option, $value) {
135 return nwdcx_halttransient($value, $option);
136 },
137 \PHP_INT_MIN,
138 2
139 );
140 }
141
142 // early cache transient/alloptions
143 if (class_exists('Nawawi\\DocketCache\\Becache')) {
144 add_action(
145 'shutdown',
146 function () {
147 try {
148 Nawawi\DocketCache\Becache::export();
149 } catch (\Throwable $e) {
150 }
151 },
152 \PHP_INT_MIN
153 );
154 }
155
156 // early cleanup transient
157 if (\function_exists('nwdcx_cleanuptransient')) {
158 add_action(
159 'shutdown',
160 'nwdcx_cleanuptransient',
161 \PHP_INT_MAX - 1
162 );
163 }
164
165 add_action(
166 'shutdown',
167 function () {
168 clearstatcache();
169 if (@is_file(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt')) {
170 @rename(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt', DOCKET_CACHE_CONTENT_PATH.'/.object-cache-after-delay.txt');
171 }
172 },
173 \PHP_INT_MAX
174 );
175 }
176
177 return;
178 }
179
180 /*
181 * Define WP Object Cache functions and classes.
182 */
183 @include_once WP_PLUGIN_DIR.'/docket-cache/includes/cache.php';
184