Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Caching
File: CacheNameSpaceTrait.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Automattic\WooCommerce\Caching;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Implements namespacing algorithm to simulate grouping and namespacing for wp_cache, memcache and other caching engines that don't support grouping natively.
[5] Fix | Delete
*
[6] Fix | Delete
* See the algorithm details here: https://github.com/memcached/memcached/wiki/ProgrammingTricks#namespacing.
[7] Fix | Delete
*
[8] Fix | Delete
* To use the namespacing algorithm in the CacheEngine class:
[9] Fix | Delete
* 1. Use a group string to identify all objects of a type.
[10] Fix | Delete
* 2. Before setting cache, prefix the cache key by using the `get_cache_prefix`.
[11] Fix | Delete
* 3. Use `invalidate_cache_group` function to invalidate all caches in entire group at once.
[12] Fix | Delete
*/
[13] Fix | Delete
trait CacheNameSpaceTrait {
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
[17] Fix | Delete
*
[18] Fix | Delete
* @param string $group Group of cache to get.
[19] Fix | Delete
* @return string Prefix.
[20] Fix | Delete
*/
[21] Fix | Delete
public static function get_cache_prefix( $group ) {
[22] Fix | Delete
// Get cache key - uses cache key wc_orders_cache_prefix to invalidate when needed.
[23] Fix | Delete
$prefix = wp_cache_get( 'wc_' . $group . '_cache_prefix', $group );
[24] Fix | Delete
[25] Fix | Delete
if ( false === $prefix ) {
[26] Fix | Delete
$prefix = microtime();
[27] Fix | Delete
wp_cache_set( 'wc_' . $group . '_cache_prefix', $prefix, $group );
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
return 'wc_cache_' . $prefix . '_';
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* Increment group cache prefix (invalidates cache).
[35] Fix | Delete
*
[36] Fix | Delete
* @param string $group Group of cache to clear.
[37] Fix | Delete
*/
[38] Fix | Delete
public static function incr_cache_prefix( $group ) {
[39] Fix | Delete
wc_deprecated_function( 'WC_Cache_Helper::incr_cache_prefix', '3.9.0', 'WC_Cache_Helper::invalidate_cache_group' );
[40] Fix | Delete
self::invalidate_cache_group( $group );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Invalidate cache group.
[45] Fix | Delete
*
[46] Fix | Delete
* @param string $group Group of cache to clear.
[47] Fix | Delete
* @since 3.9.0
[48] Fix | Delete
*/
[49] Fix | Delete
public static function invalidate_cache_group( $group ) {
[50] Fix | Delete
return wp_cache_set( 'wc_' . $group . '_cache_prefix', microtime(), $group );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Helper method to get prefixed key.
[55] Fix | Delete
*
[56] Fix | Delete
* @param string $key Key to prefix.
[57] Fix | Delete
* @param string $group Group of cache to get.
[58] Fix | Delete
*
[59] Fix | Delete
* @return string Prefixed key.
[60] Fix | Delete
*/
[61] Fix | Delete
public static function get_prefixed_key( $key, $group ) {
[62] Fix | Delete
return self::get_cache_prefix( $group ) . $key;
[63] Fix | Delete
}
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function