data ) ) { return $this->data[ $key ]; } return $default; } /** * Set cache key and value * * @param Cache key $key cache key. * @param Cache value $value cache value. */ public function set_cache( $key, $value ) { if ( isset( $this->data[ $key ] ) ) { return; } $this->data[ $key ] = $value; } /** * Unset cache by key * * @param Cache key $key cache key. */ public function un_set( $key ) { if ( isset( $this->data[ $key ] ) ) { unset( $this->data[ $key ] ); } } /** * Destruct cache items */ public function __destruct() { $keys = array_keys( $this->data ); array_walk( $keys, array( $this, 'un_set' ) ); } /** * Determine cache key. * * @param array|string $data Determine data. * * @return string */ public static function determine_cache_key( $data ) { return is_array( $data ) ? implode( '-', $data ) : (string) $data; } /** * Clear all cache key */ public function clear_cache() { $this->data = array(); } }