Edit File by line
/home/barbar84/www/wp-conte.../themes/Divi/core/componen...
File: Cache.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Core Cache implements an object cache.
[2] Fix | Delete
*
[3] Fix | Delete
* The Object Cache stores all of the cache data to memory only for the duration of the request.
[4] Fix | Delete
*
[5] Fix | Delete
* @package Core\Cache
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class that implements an object cache.
[10] Fix | Delete
*
[11] Fix | Delete
* The Object Cache is used to save on trips to the database. The
[12] Fix | Delete
* Object Cache stores all of the cache data to memory and makes the cache
[13] Fix | Delete
* contents available by using a key, which is used to name and later retrieve
[14] Fix | Delete
* the cache contents.
[15] Fix | Delete
*
[16] Fix | Delete
* @private
[17] Fix | Delete
*
[18] Fix | Delete
* @package ET\Core\Cache
[19] Fix | Delete
*/
[20] Fix | Delete
final class ET_Core_Cache {
[21] Fix | Delete
[22] Fix | Delete
/**
[23] Fix | Delete
* Cached data.
[24] Fix | Delete
*
[25] Fix | Delete
* @since 1.0.0
[26] Fix | Delete
*
[27] Fix | Delete
* @type array
[28] Fix | Delete
*/
[29] Fix | Delete
private static $cache = array();
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Adds data to the cache if it doesn't already exist.
[33] Fix | Delete
*
[34] Fix | Delete
* @since 1.0.0
[35] Fix | Delete
*
[36] Fix | Delete
* @param int|string $key What to call the contents in the cache.
[37] Fix | Delete
* @param mixed $data The contents to store in the cache.
[38] Fix | Delete
* @param string $group Optional. Where to group the cache contents. Default 'default'.
[39] Fix | Delete
* @return bool False if cache key and group already exist, true on success
[40] Fix | Delete
*/
[41] Fix | Delete
public static function add( $key, $data, $group = 'default' ) {
[42] Fix | Delete
if ( empty( $group ) ) {
[43] Fix | Delete
$group = 'default';
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
if ( self::_exists( $key, $group ) ) {
[47] Fix | Delete
return false;
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
return self::set( $key, $data, $group );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Sets the data contents into the cache.
[55] Fix | Delete
*
[56] Fix | Delete
* The cache contents is grouped by the $group parameter followed by the
[57] Fix | Delete
* $key. This allows for duplicate ids in unique groups.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 1.0.0
[60] Fix | Delete
*
[61] Fix | Delete
* @param int|string $key What to call the contents in the cache.
[62] Fix | Delete
* @param mixed $data The contents to store in the cache.
[63] Fix | Delete
* @param string $group Optional. Where to group the cache contents. Default 'default'.
[64] Fix | Delete
* @param int $expire Not Used.
[65] Fix | Delete
* @return true Always returns true.
[66] Fix | Delete
*/
[67] Fix | Delete
public static function set( $key, $data, $group = 'default' ) {
[68] Fix | Delete
if ( empty( $group ) ) {
[69] Fix | Delete
$group = 'default';
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
if ( is_object( $data ) ) {
[73] Fix | Delete
$data = clone $data;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
self::$cache[ $group ][ $key ] = $data;
[77] Fix | Delete
[78] Fix | Delete
return true;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Retrieves the cache contents, if it exists.
[83] Fix | Delete
*
[84] Fix | Delete
* The contents will be first attempted to be retrieved by searching by the
[85] Fix | Delete
* key in the cache group. If the cache is hit (success) then the contents
[86] Fix | Delete
* are returned.
[87] Fix | Delete
*
[88] Fix | Delete
* @since 1.0.0
[89] Fix | Delete
*
[90] Fix | Delete
* @param int|string $key What the contents in the cache are called.
[91] Fix | Delete
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
[92] Fix | Delete
* @return false|mixed False on failure to retrieve contents or the cache contents on success.
[93] Fix | Delete
*/
[94] Fix | Delete
public static function get( $key, $group = 'default' ) {
[95] Fix | Delete
if ( empty( $group ) ) {
[96] Fix | Delete
$group = 'default';
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
if ( self::_exists( $key, $group ) ) {
[100] Fix | Delete
if ( is_object( self::$cache[ $group ][ $key ] ) ) {
[101] Fix | Delete
return clone self::$cache[ $group ][ $key ];
[102] Fix | Delete
} else {
[103] Fix | Delete
return self::$cache[ $group ][ $key ];
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
return false;
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**
[111] Fix | Delete
* Retrieves the cache contents for entire group, if it exists.
[112] Fix | Delete
*
[113] Fix | Delete
* If the cache is hit (success) then the contents of the group
[114] Fix | Delete
* are returned.
[115] Fix | Delete
*
[116] Fix | Delete
* @since 1.0.0
[117] Fix | Delete
*
[118] Fix | Delete
* @param string $group Where the cache contents are grouped.
[119] Fix | Delete
* @return false|mixed False on failure to retrieve contents or the cache contents on success.
[120] Fix | Delete
*/
[121] Fix | Delete
public static function get_group( $group ) {
[122] Fix | Delete
if ( isset( self::$cache[ $group ] ) ) {
[123] Fix | Delete
return self::$cache[ $group ];
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
return false;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Check the cache contents, if given key and (optional) group exists.
[131] Fix | Delete
*
[132] Fix | Delete
* @since 1.0.0
[133] Fix | Delete
*
[134] Fix | Delete
* @param int|string $key What the contents in the cache are called.
[135] Fix | Delete
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
[136] Fix | Delete
* @return bool False on failure to retrieve contents or True on success.
[137] Fix | Delete
*/
[138] Fix | Delete
public static function has( $key, $group = 'default' ) {
[139] Fix | Delete
if ( empty( $group ) ) {
[140] Fix | Delete
$group = 'default';
[141] Fix | Delete
}
[142] Fix | Delete
return self::_exists( $key, $group );
[143] Fix | Delete
}
[144] Fix | Delete
[145] Fix | Delete
/**
[146] Fix | Delete
* Removes the contents of the cache key in the group.
[147] Fix | Delete
*
[148] Fix | Delete
* If the cache key does not exist in the group, then nothing will happen.
[149] Fix | Delete
*
[150] Fix | Delete
* @since 1.0.0
[151] Fix | Delete
*
[152] Fix | Delete
* @param int|string $key What the contents in the cache are called.
[153] Fix | Delete
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
[154] Fix | Delete
* @return bool False if the contents weren't deleted and true on success.
[155] Fix | Delete
*/
[156] Fix | Delete
public static function delete( $key, $group = 'default' ) {
[157] Fix | Delete
if ( empty( $group ) ) {
[158] Fix | Delete
$group = 'default';
[159] Fix | Delete
}
[160] Fix | Delete
[161] Fix | Delete
if ( ! self::_exists( $key, $group ) ) {
[162] Fix | Delete
return false;
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
unset( self::$cache[ $group ][ $key ] );
[166] Fix | Delete
return true;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Clears the object cache of all data.
[171] Fix | Delete
*
[172] Fix | Delete
* @since 1.0.0
[173] Fix | Delete
*
[174] Fix | Delete
* @return true Always returns true.
[175] Fix | Delete
*/
[176] Fix | Delete
public static function flush() {
[177] Fix | Delete
self::$cache = array();
[178] Fix | Delete
[179] Fix | Delete
return true;
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
/**
[183] Fix | Delete
* Serves as a utility function to determine whether a key exists in the cache.
[184] Fix | Delete
*
[185] Fix | Delete
* @since 1.0.0
[186] Fix | Delete
* @private
[187] Fix | Delete
*
[188] Fix | Delete
* @param int|string $key Cache key to check for existence.
[189] Fix | Delete
* @param string $group Cache group for the key existence check.
[190] Fix | Delete
* @return bool Whether the key exists in the cache for the given group.
[191] Fix | Delete
*/
[192] Fix | Delete
private static function _exists( $key, $group ) {
[193] Fix | Delete
return isset( self::$cache[ $group ] ) && isset( self::$cache[ $group ][ $key ] );
[194] Fix | Delete
}
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
[198] Fix | Delete
if ( ! function_exists( 'et_core_cache_add' ) ) :
[199] Fix | Delete
/**
[200] Fix | Delete
* Adds data to the cache if it doesn't already exist.
[201] Fix | Delete
*
[202] Fix | Delete
* @since 1.0.0
[203] Fix | Delete
*
[204] Fix | Delete
* @param int|string $key What to call the contents in the cache.
[205] Fix | Delete
* @param mixed $data The contents to store in the cache.
[206] Fix | Delete
* @param string $group Optional. Where to group the cache contents. Default 'default'.
[207] Fix | Delete
* @return bool False if cache key and group already exist, true on success
[208] Fix | Delete
*/
[209] Fix | Delete
function et_core_cache_add( $key, $data, $group = '' ) {
[210] Fix | Delete
return ET_Core_Cache::add( $key, $data, $group );
[211] Fix | Delete
}
[212] Fix | Delete
endif;
[213] Fix | Delete
[214] Fix | Delete
if ( ! function_exists( 'et_core_cache_set' ) ) :
[215] Fix | Delete
/**
[216] Fix | Delete
* Sets the data contents into the cache.
[217] Fix | Delete
*
[218] Fix | Delete
* The cache contents is grouped by the $group parameter followed by the
[219] Fix | Delete
* $key. This allows for duplicate ids in unique groups.
[220] Fix | Delete
*
[221] Fix | Delete
* @since 1.0.0
[222] Fix | Delete
*
[223] Fix | Delete
* @param int|string $key What to call the contents in the cache.
[224] Fix | Delete
* @param mixed $data The contents to store in the cache.
[225] Fix | Delete
* @param string $group Optional. Where to group the cache contents. Default 'default'.
[226] Fix | Delete
* @param int $expire Not Used.
[227] Fix | Delete
* @return true Always returns true.
[228] Fix | Delete
*/
[229] Fix | Delete
function et_core_cache_set( $key, $data, $group = '' ) {
[230] Fix | Delete
return ET_Core_Cache::set( $key, $data, $group );
[231] Fix | Delete
}
[232] Fix | Delete
endif;
[233] Fix | Delete
[234] Fix | Delete
if ( ! function_exists( 'et_core_cache_get' ) ) :
[235] Fix | Delete
/**
[236] Fix | Delete
* Retrieves the cache contents, if it exists.
[237] Fix | Delete
*
[238] Fix | Delete
* The contents will be first attempted to be retrieved by searching by the
[239] Fix | Delete
* key in the cache group. If the cache is hit (success) then the contents
[240] Fix | Delete
* are returned.
[241] Fix | Delete
*
[242] Fix | Delete
* @since 1.0.0
[243] Fix | Delete
*
[244] Fix | Delete
* @param int|string $key What the contents in the cache are called.
[245] Fix | Delete
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
[246] Fix | Delete
* @return false|mixed False on failure to retrieve contents or the cache contents on success.
[247] Fix | Delete
*/
[248] Fix | Delete
function et_core_cache_get( $key, $group = '' ) {
[249] Fix | Delete
return ET_Core_Cache::get( $key, $group );
[250] Fix | Delete
}
[251] Fix | Delete
endif;
[252] Fix | Delete
[253] Fix | Delete
if ( ! function_exists( 'et_core_cache_get_group' ) ) :
[254] Fix | Delete
/**
[255] Fix | Delete
* Retrieves the cache contents for entire group, if it exists.
[256] Fix | Delete
*
[257] Fix | Delete
* If the cache is hit (success) then the contents of the group
[258] Fix | Delete
* are returned.
[259] Fix | Delete
*
[260] Fix | Delete
* @since 1.0.0
[261] Fix | Delete
*
[262] Fix | Delete
* @param string $group Where the cache contents are grouped.
[263] Fix | Delete
* @return false|mixed False on failure to retrieve contents or the cache contents on success.
[264] Fix | Delete
*/
[265] Fix | Delete
function et_core_cache_get_group( $group ) {
[266] Fix | Delete
return ET_Core_Cache::get_group( $group );
[267] Fix | Delete
}
[268] Fix | Delete
endif;
[269] Fix | Delete
[270] Fix | Delete
if ( ! function_exists( 'et_core_cache_has' ) ) :
[271] Fix | Delete
/**
[272] Fix | Delete
* Check the cache contents, if given key and (optional) group exists.
[273] Fix | Delete
*
[274] Fix | Delete
* @since 1.0.0
[275] Fix | Delete
*
[276] Fix | Delete
* @param int|string $key What the contents in the cache are called.
[277] Fix | Delete
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
[278] Fix | Delete
* @return bool False on failure to retrieve contents or True on success.
[279] Fix | Delete
*/
[280] Fix | Delete
function et_core_cache_has( $key, $group = '' ) {
[281] Fix | Delete
return ET_Core_Cache::has( $key, $group );
[282] Fix | Delete
}
[283] Fix | Delete
endif;
[284] Fix | Delete
[285] Fix | Delete
if ( ! function_exists( 'et_core_cache_delete' ) ) :
[286] Fix | Delete
/**
[287] Fix | Delete
* Removes the contents of the cache key in the group.
[288] Fix | Delete
*
[289] Fix | Delete
* If the cache key does not exist in the group, then nothing will happen.
[290] Fix | Delete
*
[291] Fix | Delete
* @since 1.0.0
[292] Fix | Delete
*
[293] Fix | Delete
* @param int|string $key What the contents in the cache are called.
[294] Fix | Delete
* @param string $group Optional. Where the cache contents are grouped. Default 'default'.
[295] Fix | Delete
* @return bool False if the contents weren't deleted and true on success.
[296] Fix | Delete
*/
[297] Fix | Delete
function et_core_cache_delete( $key, $group = '' ) {
[298] Fix | Delete
return ET_Core_Cache::delete( $key, $group );
[299] Fix | Delete
}
[300] Fix | Delete
endif;
[301] Fix | Delete
[302] Fix | Delete
if ( ! function_exists( 'et_core_cache_flush' ) ) :
[303] Fix | Delete
/**
[304] Fix | Delete
* Clears the object cache of all data.
[305] Fix | Delete
*
[306] Fix | Delete
* @since 1.0.0
[307] Fix | Delete
* @return true Always returns true.
[308] Fix | Delete
*/
[309] Fix | Delete
function et_core_cache_flush() {
[310] Fix | Delete
return ET_Core_Cache::flush();
[311] Fix | Delete
}
[312] Fix | Delete
endif;
[313] Fix | Delete
[314] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function