clean_site_details_cache()
云策文档标注
概述
clean_site_details_cache() 函数用于清理指定站点的站点详情缓存,包括 'site-details' 和 'blog-details' 缓存组。它接受一个可选的站点 ID 参数,默认为当前站点 ID。
关键要点
- 函数清理站点详情缓存,通过 wp_cache_delete() 删除 'site-details' 和 'blog-details' 缓存组中的条目。
- 参数 $site_id 为可选整数,默认值为 0,表示使用 get_current_blog_id() 获取当前站点 ID。
- 函数在 WordPress 4.7.4 版本中引入。
代码示例
function clean_site_details_cache( $site_id = 0 ) {
$site_id = (int) $site_id;
if ( ! $site_id ) {
$site_id = get_current_blog_id();
}
wp_cache_delete( $site_id, 'site-details' );
wp_cache_delete( $site_id, 'blog-details' );
}注意事项
- 确保在需要更新站点详情时调用此函数,以避免缓存数据过时。
- 相关函数包括 wp_cache_delete() 和 get_current_blog_id(),用于缓存操作和获取站点 ID。
原文内容
Cleans the site details cache for a site.
Parameters
$site_idintoptional-
Site ID. Default is the current site ID.
Source
function clean_site_details_cache( $site_id = 0 ) {
$site_id = (int) $site_id;
if ( ! $site_id ) {
$site_id = get_current_blog_id();
}
wp_cache_delete( $site_id, 'site-details' );
wp_cache_delete( $site_id, 'blog-details' );
}
Changelog
| Version | Description |
|---|---|
| 4.7.4 | Introduced. |