wp_suspend_cache_invalidation()
云策文档标注
概述
wp_suspend_cache_invalidation() 函数用于控制缓存失效的暂停与启用,适用于批量操作如导入时避免频繁缓存失效。
关键要点
- 函数通过全局变量 $_wp_suspend_cache_invalidation 管理缓存失效状态
- 参数 $suspend 可选,默认为 true 表示暂停缓存失效
- 返回当前暂停设置,便于恢复原始状态
- 调用者需确保暂停期间操作不会导致缓存不一致
代码示例
function wp_suspend_cache_invalidation( $suspend = true ) {
global $_wp_suspend_cache_invalidation;
$current_suspend = $_wp_suspend_cache_invalidation;
$_wp_suspend_cache_invalidation = $suspend;
return $current_suspend;
}注意事项
- 在暂停缓存失效期间,需谨慎操作以避免缓存数据不一致
- 此函数自 WordPress 2.7.0 版本引入
原文内容
Suspends cache invalidation.
Description
Turns cache invalidation on and off. Useful during imports where you don’t want to do invalidations every time a post is inserted. Callers must be sure that what they are doing won’t lead to an inconsistent cache when invalidation is suspended.
Parameters
$suspendbooloptional-
Whether to suspend or enable cache invalidation.
Default:
true
Source
function wp_suspend_cache_invalidation( $suspend = true ) {
global $_wp_suspend_cache_invalidation;
$current_suspend = $_wp_suspend_cache_invalidation;
$_wp_suspend_cache_invalidation = $suspend;
return $current_suspend;
}
Changelog
| Version | Description |
|---|---|
| 2.7.0 | Introduced. |