lpers->isDev() && 80 < mb_strlen( $key, 'UTF-8' ) ) { throw new \Exception( 'You are using a cache key that is too large, shorten your key and try again: [' . esc_html( $key ) . ']' ); } return $key; } /** * Clears all of our cache. * * @since 4.1.5 * * @return void */ public function clear() { if ( $this->prefix ) { $this->clearPrefix( '' ); return; } // If we find the activation redirect, we'll need to reset it after clearing. $activationRedirect = $this->get( 'activation_redirect' ); aioseo()->core->db->truncate( $this->table )->run(); $this->clearStatic(); if ( $activationRedirect ) { $this->update( 'activation_redirect', $activationRedirect, 30 ); } // Bust the tableExists and columnExists cache. aioseo()->internalOptions->database->installedTables = ''; } /** * Clears all of our cache under a certain prefix. * * @since 4.1.5 * * @param string $prefix A prefix to clear or empty to clear everything. * @return void */ public function clearPrefix( $prefix ) { $prefix = $this->prepareKey( $prefix ); aioseo()->core->db->delete( $this->table ) ->whereRaw( "`key` LIKE '$prefix%'" ) ->run(); $this->clearStaticPrefix( $prefix ); } /** * Clears all of our static in-memory cache of a prefix. * * @since 4.1.5 * * @param string $prefix A prefix to clear. * @return void */ private function clearStaticPrefix( $prefix ) { $prefix = $this->prepareKey( $prefix ); foreach ( array_keys( self::$cache ) as $key ) { if ( 0 === strpos( $key, $prefix ) ) { unset( self::$cache[ $key ] ); } } } /** * Clears all of our static in-memory cache. * * @since 4.1.5 * * @param string $key A key to clear. * @return void */ private function clearStatic( $key = null ) { if ( empty( $key ) ) { self::$cache = []; return; } unset( self::$cache[ $this->prepareKey( $key ) ] ); } /** * Clears all of our static in-memory cache or the cache for a single given key. * * @since 4.7.1 * * @param string $key A key to clear (optional). * @param string $value A value to update (optional). * @return void */ private function updateStatic( $key = null, $value = null ) { if ( empty( $key ) ) { $this->clearStatic( $key ); return; } self::$cache[ $this->prepareKey( $key ) ] = $value; } /** * Returns the cache table name. * * @since 4.1.5 * * @return string */ public function getTableName() { return $this->table; } }