安装插件 :Redis Object Cache

wp-memcached

WordPress为我们提供了使用对象缓存的函数,方便我们使用对象缓存。

wp_cache_add():添加数据到缓存中,如果数据已存在,返回flase
wp_cache_set():添加数据到缓存中,如果数据已存在,会覆盖数据
wp_cache_get():获取缓存中的数据,如果数据不存在,返回false
wp_cache_delete():从缓存中删除数据
wp_cache_replace():替换缓存中的数据,类似wp_cache_set,但是如果数据不存在,不自动添加
wp_cache_flush():清除所有缓存

WordPress对象缓存使用使用示例

$result=wp_cache_get('my_result');
if(false===$result){
    $result=$wpdb->get_results($query);
    wp_cache_set('my_result',$result);
}