key_group = $this->key_group_parent . $this->key_group_child; } /** * Set cache * * @param string $key * @param mixed $data * @param int $expire */ public function set_cache( string $key, $data, int $expire = 0 ) { wp_cache_set( $key, $data, $this->key_group, $expire ); } /** * Get cache * * @param string $key * @return false|mixed */ public function get_cache( string $key ) { return wp_cache_get( $key, $this->key_group ); } /** * Set value for first load page on one process * Apply for query call same * * @param string $type * @param string $key * @param $val mixed * * @author tungnx * @version 1.0.0 * @sicne 4.1.4.1 * @return false|mixed|string */ public static function cache_load_first( string $type = 'get', string $key = '', $val = '' ) { static $first_set_value = array(); if ( 'get' === $type ) { if ( ! array_key_exists( $key, $first_set_value ) ) { return false; } else { return $first_set_value[ $key ]; } } elseif ( 'set' === $type ) { $first_set_value[ $key ] = $val; return $first_set_value[ $key ]; } } /** * Clear cache by key * * @param $key */ public function clear( $key ) { wp_cache_delete( $key, $this->key_group ); } public function clear_all() { wp_cache_flush(); } }