wp_cache_add( $key, $data, $group, $expire )
wp_cache_set( $key, $data, $group, $expire )
Run Code Online (Sandbox Code Playgroud)
我想利用这些不错的功能。我或多或少明白了工作的逻辑。
但是 WP 在哪里存储先前缓存的查询的答案呢?它还保留数据库吗?或者是作为临时 JSON 文件保存到 root 中?
这是一个简单的例子。
$result = wp_cache_get( 'my_result' );
if ( false === $result ) {
$result = $wpdb->get_results( $query );
wp_cache_set( 'my_result', $result );
}
// Do something with $result;
Run Code Online (Sandbox Code Playgroud) wordpress ×1