cdn
7 months ago
data_structure
7 months ago
activation.cls.php
7 months ago
admin-display.cls.php
7 months ago
admin-settings.cls.php
7 months ago
admin.cls.php
7 months ago
api.cls.php
7 months ago
avatar.cls.php
7 months ago
base.cls.php
7 months ago
cdn.cls.php
7 months ago
cloud.cls.php
7 months ago
conf.cls.php
7 months ago
control.cls.php
7 months ago
core.cls.php
7 months ago
crawler-map.cls.php
7 months ago
crawler.cls.php
7 months ago
css.cls.php
7 months ago
data.cls.php
7 months ago
data.upgrade.func.php
7 months ago
db-optm.cls.php
7 months ago
debug2.cls.php
7 months ago
doc.cls.php
7 months ago
error.cls.php
7 months ago
esi.cls.php
7 months ago
file.cls.php
7 months ago
gui.cls.php
7 months ago
health.cls.php
7 months ago
htaccess.cls.php
7 months ago
img-optm.cls.php
7 months ago
import.cls.php
7 months ago
import.preset.cls.php
7 months ago
lang.cls.php
7 months ago
localization.cls.php
7 months ago
media.cls.php
7 months ago
metabox.cls.php
7 months ago
object-cache-wp.cls.php
7 months ago
object-cache.cls.php
7 months ago
object.lib.php
7 months ago
optimize.cls.php
7 months ago
optimizer.cls.php
7 months ago
placeholder.cls.php
7 months ago
purge.cls.php
7 months ago
report.cls.php
7 months ago
rest.cls.php
7 months ago
root.cls.php
7 months ago
router.cls.php
7 months ago
str.cls.php
7 months ago
tag.cls.php
7 months ago
task.cls.php
7 months ago
tool.cls.php
7 months ago
ucss.cls.php
7 months ago
utility.cls.php
7 months ago
vary.cls.php
7 months ago
vpi.cls.php
7 months ago
object.lib.php
419 lines
| 1 | <?php |
| 2 | /** |
| 3 | * LiteSpeed Object Cache Library |
| 4 | * |
| 5 | * @since 1.8 |
| 6 | * @package LiteSpeed |
| 7 | */ |
| 8 | |
| 9 | defined( 'WPINC' ) || exit(); |
| 10 | |
| 11 | if (!function_exists('litespeed_exception_handler')) { |
| 12 | /** |
| 13 | * Handle exception |
| 14 | * |
| 15 | * Converts PHP errors into exceptions for better error handling. |
| 16 | * |
| 17 | * @since 1.8 |
| 18 | * @access public |
| 19 | * @param int $errno Error level. |
| 20 | * @param string $errstr Error message. |
| 21 | * @param string $errfile File where the error occurred. |
| 22 | * @param int $errline Line number where the error occurred. |
| 23 | * @throws \ErrorException Error msg. |
| 24 | */ |
| 25 | function litespeed_exception_handler( $errno, $errstr, $errfile, $errline ) { |
| 26 | throw new \ErrorException( esc_html( $errstr ), 0, esc_html( $errno ), esc_html( $errfile ), esc_html( $errline ) ); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | require_once __DIR__ . '/object-cache.cls.php'; |
| 31 | require_once __DIR__ . '/object-cache-wp.cls.php'; |
| 32 | |
| 33 | /** |
| 34 | * Sets up Object Cache Global and assigns it. |
| 35 | * |
| 36 | * Initializes the global object cache instance. |
| 37 | * |
| 38 | * @since 1.8 |
| 39 | * @access public |
| 40 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 41 | */ |
| 42 | function wp_cache_init() { |
| 43 | // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited |
| 44 | $GLOBALS['wp_object_cache'] = WP_Object_Cache::get_instance(); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Adds data to the cache, if the cache key doesn't already exist. |
| 49 | * |
| 50 | * @since 1.8 |
| 51 | * @access public |
| 52 | * @see WP_Object_Cache::add() |
| 53 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 54 | * |
| 55 | * @param int|string $key The cache key to use for retrieval later. |
| 56 | * @param mixed $data The data to add to the cache. |
| 57 | * @param string $group Optional. The group to add the cache to. Enables the same key |
| 58 | * to be used across groups. Default empty. |
| 59 | * @param int $expire Optional. When the cache data should expire, in seconds. |
| 60 | * Default 0 (no expiration). |
| 61 | * @return bool True on success, false if cache key and group already exist. |
| 62 | */ |
| 63 | function wp_cache_add( $key, $data, $group = '', $expire = 0 ) { |
| 64 | global $wp_object_cache; |
| 65 | |
| 66 | return $wp_object_cache->add( $key, $data, $group, (int) $expire ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Adds multiple values to the cache in one call. |
| 71 | * |
| 72 | * @since 5.4 |
| 73 | * @access public |
| 74 | * @see WP_Object_Cache::add_multiple() |
| 75 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 76 | * |
| 77 | * @param array $data Array of keys and values to be set. |
| 78 | * @param string $group Optional. Where the cache contents are grouped. Default empty. |
| 79 | * @param int $expire Optional. When to expire the cache contents, in seconds. |
| 80 | * Default 0 (no expiration). |
| 81 | * @return bool[] Array of return values, grouped by key. Each value is either |
| 82 | * true on success, or false if cache key and group already exist. |
| 83 | */ |
| 84 | function wp_cache_add_multiple( array $data, $group = '', $expire = 0 ) { |
| 85 | global $wp_object_cache; |
| 86 | |
| 87 | return $wp_object_cache->add_multiple( $data, $group, $expire ); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Replaces the contents of the cache with new data. |
| 92 | * |
| 93 | * @since 1.8 |
| 94 | * @access public |
| 95 | * @see WP_Object_Cache::replace() |
| 96 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 97 | * |
| 98 | * @param int|string $key The key for the cache data that should be replaced. |
| 99 | * @param mixed $data The new data to store in the cache. |
| 100 | * @param string $group Optional. The group for the cache data that should be replaced. |
| 101 | * Default empty. |
| 102 | * @param int $expire Optional. When to expire the cache contents, in seconds. |
| 103 | * Default 0 (no expiration). |
| 104 | * @return bool True if contents were replaced, false if original value does not exist. |
| 105 | */ |
| 106 | function wp_cache_replace( $key, $data, $group = '', $expire = 0 ) { |
| 107 | global $wp_object_cache; |
| 108 | |
| 109 | return $wp_object_cache->replace( $key, $data, $group, (int) $expire ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Saves the data to the cache. |
| 114 | * |
| 115 | * Differs from wp_cache_add() and wp_cache_replace() in that it will always write data. |
| 116 | * |
| 117 | * @since 1.8 |
| 118 | * @access public |
| 119 | * @see WP_Object_Cache::set() |
| 120 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 121 | * |
| 122 | * @param int|string $key The cache key to use for retrieval later. |
| 123 | * @param mixed $data The contents to store in the cache. |
| 124 | * @param string $group Optional. Where to group the cache contents. Enables the same key |
| 125 | * to be used across groups. Default empty. |
| 126 | * @param int $expire Optional. When to expire the cache contents, in seconds. |
| 127 | * Default 0 (no expiration). |
| 128 | * @return bool True on success, false on failure. |
| 129 | */ |
| 130 | function wp_cache_set( $key, $data, $group = '', $expire = 0 ) { |
| 131 | global $wp_object_cache; |
| 132 | |
| 133 | return $wp_object_cache->set( $key, $data, $group, (int) $expire ); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Sets multiple values to the cache in one call. |
| 138 | * |
| 139 | * @since 5.4 |
| 140 | * @access public |
| 141 | * @see WP_Object_Cache::set_multiple() |
| 142 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 143 | * |
| 144 | * @param array $data Array of keys and values to be set. |
| 145 | * @param string $group Optional. Where the cache contents are grouped. Default empty. |
| 146 | * @param int $expire Optional. When to expire the cache contents, in seconds. |
| 147 | * Default 0 (no expiration). |
| 148 | * @return bool[] Array of return values, grouped by key. Each value is either |
| 149 | * true on success, or false on failure. |
| 150 | */ |
| 151 | function wp_cache_set_multiple( array $data, $group = '', $expire = 0 ) { |
| 152 | global $wp_object_cache; |
| 153 | |
| 154 | return $wp_object_cache->set_multiple( $data, $group, $expire ); |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Retrieves the cache contents from the cache by key and group. |
| 159 | * |
| 160 | * @since 1.8 |
| 161 | * @access public |
| 162 | * @see WP_Object_Cache::get() |
| 163 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 164 | * |
| 165 | * @param int|string $key The key under which the cache contents are stored. |
| 166 | * @param string $group Optional. Where the cache contents are grouped. Default empty. |
| 167 | * @param bool $force Optional. Whether to force an update of the local cache |
| 168 | * from the persistent cache. Default false. |
| 169 | * @param bool $found Optional. Whether the key was found in the cache (passed by reference). |
| 170 | * Disambiguates a return of false, a storable value. Default null. |
| 171 | * @return mixed|false The cache contents on success, false on failure to retrieve contents. |
| 172 | */ |
| 173 | function wp_cache_get( $key, $group = '', $force = false, &$found = null ) { |
| 174 | global $wp_object_cache; |
| 175 | |
| 176 | return $wp_object_cache->get( $key, $group, $force, $found ); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Retrieves multiple values from the cache in one call. |
| 181 | * |
| 182 | * @since 5.4 |
| 183 | * @access public |
| 184 | * @see WP_Object_Cache::get_multiple() |
| 185 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 186 | * |
| 187 | * @param array $keys Array of keys under which the cache contents are stored. |
| 188 | * @param string $group Optional. Where the cache contents are grouped. Default empty. |
| 189 | * @param bool $force Optional. Whether to force an update of the local cache |
| 190 | * from the persistent cache. Default false. |
| 191 | * @return array Array of return values, grouped by key. Each value is either |
| 192 | * the cache contents on success, or false on failure. |
| 193 | */ |
| 194 | function wp_cache_get_multiple( $keys, $group = '', $force = false ) { |
| 195 | global $wp_object_cache; |
| 196 | |
| 197 | return $wp_object_cache->get_multiple( $keys, $group, $force ); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Removes the cache contents matching key and group. |
| 202 | * |
| 203 | * @since 1.8 |
| 204 | * @access public |
| 205 | * @see WP_Object_Cache::delete() |
| 206 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 207 | * |
| 208 | * @param int|string $key What the contents in the cache are called. |
| 209 | * @param string $group Optional. Where the cache contents are grouped. Default empty. |
| 210 | * @return bool True on successful removal, false on failure. |
| 211 | */ |
| 212 | function wp_cache_delete( $key, $group = '' ) { |
| 213 | global $wp_object_cache; |
| 214 | |
| 215 | return $wp_object_cache->delete( $key, $group ); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Deletes multiple values from the cache in one call. |
| 220 | * |
| 221 | * @since 5.4 |
| 222 | * @access public |
| 223 | * @see WP_Object_Cache::delete_multiple() |
| 224 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 225 | * |
| 226 | * @param array $keys Array of keys under which the cache to deleted. |
| 227 | * @param string $group Optional. Where the cache contents are grouped. Default empty. |
| 228 | * @return bool[] Array of return values, grouped by key. Each value is either |
| 229 | * true on success, or false if the contents were not deleted. |
| 230 | */ |
| 231 | function wp_cache_delete_multiple( array $keys, $group = '' ) { |
| 232 | global $wp_object_cache; |
| 233 | |
| 234 | return $wp_object_cache->delete_multiple( $keys, $group ); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Increments numeric cache item's value. |
| 239 | * |
| 240 | * @since 1.8 |
| 241 | * @access public |
| 242 | * @see WP_Object_Cache::incr() |
| 243 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 244 | * |
| 245 | * @param int|string $key The key for the cache contents that should be incremented. |
| 246 | * @param int $offset Optional. The amount by which to increment the item's value. |
| 247 | * Default 1. |
| 248 | * @param string $group Optional. The group the key is in. Default empty. |
| 249 | * @return int|false The item's new value on success, false on failure. |
| 250 | */ |
| 251 | function wp_cache_incr( $key, $offset = 1, $group = '' ) { |
| 252 | global $wp_object_cache; |
| 253 | |
| 254 | return $wp_object_cache->incr( $key, $offset, $group ); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Decrements numeric cache item's value. |
| 259 | * |
| 260 | * @since 1.8 |
| 261 | * @access public |
| 262 | * @see WP_Object_Cache::decr() |
| 263 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 264 | * |
| 265 | * @param int|string $key The cache key to decrement. |
| 266 | * @param int $offset Optional. The amount by which to decrement the item's value. |
| 267 | * Default 1. |
| 268 | * @param string $group Optional. The group the key is in. Default empty. |
| 269 | * @return int|false The item's new value on success, false on failure. |
| 270 | */ |
| 271 | function wp_cache_decr( $key, $offset = 1, $group = '' ) { |
| 272 | global $wp_object_cache; |
| 273 | |
| 274 | return $wp_object_cache->decr( $key, $offset, $group ); |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Removes all cache items. |
| 279 | * |
| 280 | * @since 1.8 |
| 281 | * @access public |
| 282 | * @see WP_Object_Cache::flush() |
| 283 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 284 | * |
| 285 | * @return bool True on success, false on failure. |
| 286 | */ |
| 287 | function wp_cache_flush() { |
| 288 | global $wp_object_cache; |
| 289 | |
| 290 | return $wp_object_cache->flush(); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Removes all cache items from the in-memory runtime cache. |
| 295 | * |
| 296 | * @since 5.4 |
| 297 | * @access public |
| 298 | * @see WP_Object_Cache::flush_runtime() |
| 299 | * |
| 300 | * @return bool True on success, false on failure. |
| 301 | */ |
| 302 | function wp_cache_flush_runtime() { |
| 303 | global $wp_object_cache; |
| 304 | |
| 305 | return $wp_object_cache->flush_runtime(); |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Removes all cache items in a group, if the object cache implementation supports it. |
| 310 | * |
| 311 | * Before calling this function, always check for group flushing support using the |
| 312 | * `wp_cache_supports( 'flush_group' )` function. |
| 313 | * |
| 314 | * @since 5.4 |
| 315 | * @access public |
| 316 | * @see WP_Object_Cache::flush_group() |
| 317 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 318 | * |
| 319 | * @param string $group Name of group to remove from cache. |
| 320 | * @return bool True if group was flushed, false otherwise. |
| 321 | */ |
| 322 | function wp_cache_flush_group( $group ) { |
| 323 | global $wp_object_cache; |
| 324 | |
| 325 | return $wp_object_cache->flush_group( $group ); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Determines whether the object cache implementation supports a particular feature. |
| 330 | * |
| 331 | * @since 5.4 |
| 332 | * @access public |
| 333 | * |
| 334 | * @param string $feature Name of the feature to check for. Possible values include: |
| 335 | * 'add_multiple', 'set_multiple', 'get_multiple', 'delete_multiple', |
| 336 | * 'flush_runtime', 'flush_group'. |
| 337 | * @return bool True if the feature is supported, false otherwise. |
| 338 | */ |
| 339 | function wp_cache_supports( $feature ) { |
| 340 | switch ( $feature ) { |
| 341 | case 'add_multiple': |
| 342 | case 'set_multiple': |
| 343 | case 'get_multiple': |
| 344 | case 'delete_multiple': |
| 345 | case 'flush_runtime': |
| 346 | return true; |
| 347 | |
| 348 | case 'flush_group': |
| 349 | default: |
| 350 | return false; |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | /** |
| 355 | * Closes the cache. |
| 356 | * |
| 357 | * This function has ceased to do anything since WordPress 2.5. The |
| 358 | * functionality was removed along with the rest of the persistent cache. |
| 359 | * |
| 360 | * This does not mean that plugins can't implement this function when they need |
| 361 | * to make sure that the cache is cleaned up after WordPress no longer needs it. |
| 362 | * |
| 363 | * @since 1.8 |
| 364 | * @access public |
| 365 | * |
| 366 | * @return true Always returns true. |
| 367 | */ |
| 368 | function wp_cache_close() { |
| 369 | return true; |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * Adds a group or set of groups to the list of global groups. |
| 374 | * |
| 375 | * @since 1.8 |
| 376 | * @access public |
| 377 | * @see WP_Object_Cache::add_global_groups() |
| 378 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 379 | * |
| 380 | * @param string|string[] $groups A group or an array of groups to add. |
| 381 | */ |
| 382 | function wp_cache_add_global_groups( $groups ) { |
| 383 | global $wp_object_cache; |
| 384 | |
| 385 | $wp_object_cache->add_global_groups( $groups ); |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Adds a group or set of groups to the list of non-persistent groups. |
| 390 | * |
| 391 | * @since 1.8 |
| 392 | * @access public |
| 393 | * |
| 394 | * @param string|string[] $groups A group or an array of groups to add. |
| 395 | */ |
| 396 | function wp_cache_add_non_persistent_groups( $groups ) { |
| 397 | global $wp_object_cache; |
| 398 | |
| 399 | $wp_object_cache->add_non_persistent_groups( $groups ); |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * Switches the internal blog ID. |
| 404 | * |
| 405 | * This changes the blog id used to create keys in blog specific groups. |
| 406 | * |
| 407 | * @since 1.8 |
| 408 | * @access public |
| 409 | * @see WP_Object_Cache::switch_to_blog() |
| 410 | * @global WP_Object_Cache $wp_object_cache Object cache global instance. |
| 411 | * |
| 412 | * @param int $blog_id Site ID. |
| 413 | */ |
| 414 | function wp_cache_switch_to_blog( $blog_id ) { |
| 415 | global $wp_object_cache; |
| 416 | |
| 417 | $wp_object_cache->switch_to_blog( $blog_id ); |
| 418 | } |
| 419 |