PluginProbe
Docket Cache – Object Cache Accelerator / 22.07.04
Docket Cache – Object Cache Accelerator v22.07.04
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.04, at includes/object-cache.php

188 lines 5.2 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.04
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. It happen on redirection.
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 * Just for development, it may cause uncertain results.
43 */
44 if (\defined('DOCKET_CACHE_IGNORE_REQUEST') && \is_array(DOCKET_CACHE_IGNORE_REQUEST) && !empty($_REQUEST)) {
45 if (array_intersect(DOCKET_CACHE_IGNORE_REQUEST, array_keys($_REQUEST))) {
46 return;
47 }
48 }
49
50 /*
51 * Determine if WP_CONTENT_DIR is exists.
52 */
53 if (!\defined('WP_CONTENT_DIR')) {
54 \define('WP_CONTENT_DIR', ABSPATH.'wp-content');
55 }
56
57 /*
58 * Determine if WP_PLUGIN_DIR is exists.
59 */
60 if (!\defined('WP_PLUGIN_DIR')) {
61 \define('WP_PLUGIN_DIR', WP_CONTENT_DIR.'/plugins');
62 }
63
64 /*
65 * Determine if DOCKET_CACHE_CONTENT_PATH is exists.
66 */
67 if (!\defined('DOCKET_CACHE_CONTENT_PATH')) {
68 \define('DOCKET_CACHE_CONTENT_PATH', WP_CONTENT_DIR);
69 }
70
71 /*
72 * Determine if docket object cache class and functions exists.
73 */
74 if (!@is_file(WP_PLUGIN_DIR.'/docket-cache/includes/cache.php')) {
75 return;
76 }
77
78 /*
79 * Determine if docket cache autoload exists.
80 */
81 if (!@is_file(WP_PLUGIN_DIR.'/docket-cache/includes/load.php')) {
82 return;
83 }
84
85 /*
86 * Determine if we can load docket cache library.
87 */
88 @include_once WP_PLUGIN_DIR.'/docket-cache/includes/load.php';
89 if (!class_exists('Nawawi\\DocketCache\\Plugin') || !class_exists('Nawawi\\DocketCache\\Constans') || !class_exists('Nawawi\\DocketCache\\Filesystem') || !\function_exists('nwdcx_constfx')) {
90 return;
91 }
92
93 /*
94 * Check if doing flush.
95 */
96 if (@is_file(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-flush.txt')) {
97 if (time() > @filemtime(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-flush.txt')) {
98 @unlink(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-flush.txt');
99 }
100
101 return;
102 }
103
104 /*
105 * Determine if we're on multinetwork and has object cache locking.
106 */
107 if (\function_exists('nwdcx_network_ignore') && nwdcx_network_ignore()) {
108 return;
109 }
110
111 /*
112 * Check for object-cache-delay.txt file.
113 */
114 if (@is_file(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt')) {
115 if (!\function_exists('add_action')) {
116 return;
117 }
118
119 if (time() > @filemtime(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt')) {
120 if (!\function_exists('nwdcx_halttransient')) {
121 // prevent from transient save to db before replace with our dropin
122 function nwdcx_halttransient($value, $option, $old_value = '')
123 {
124 if (false !== strpos($option, '_transient_')) {
125 return false;
126 }
127
128 return $value;
129 }
130
131 add_filter('pre_update_option', 'nwdcx_halttransient', \PHP_INT_MIN, 3);
132 add_filter('pre_get_option', 'nwdcx_halttransient', \PHP_INT_MIN, 3);
133 add_filter(
134 'added_option',
135 function ($option, $value) {
136 return nwdcx_halttransient($value, $option);
137 },
138 \PHP_INT_MIN,
139 2
140 );
141 }
142
143 if (class_exists('Nawawi\\DocketCache\\Becache')) {
144 // early cache transient/alloptions
145 add_action(
146 'shutdown',
147 function () {
148 try {
149 Nawawi\DocketCache\Becache::export();
150 } catch (\Throwable $e) {
151 }
152 },
153 \PHP_INT_MIN
154 );
155
156 // early cleanup transient
157 add_action(
158 'shutdown',
159 function () {
160 try {
161 Nawawi\DocketCache\Becache::cleanup_transient();
162 } catch (\Throwable $e) {
163 }
164 },
165 \PHP_INT_MAX - 1
166 );
167 }
168
169 add_action(
170 'shutdown',
171 function () {
172 clearstatcache();
173 if (@is_file(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt')) {
174 @rename(DOCKET_CACHE_CONTENT_PATH.'/.object-cache-delay.txt', DOCKET_CACHE_CONTENT_PATH.'/.object-cache-after-delay.txt');
175 }
176 },
177 \PHP_INT_MAX
178 );
179 }
180
181 return;
182 }
183
184 /*
185 * Define WP Object Cache functions and classes.
186 */
187 @include_once WP_PLUGIN_DIR.'/docket-cache/includes/cache.php';
188