wp_cache_reset()
云策文档标注
概述
wp_cache_reset() 是一个已弃用的 WordPress 函数,用于重置内部缓存键和结构。它主要用于在博客或站点 ID 变更时清理缓存,但现已被 wp_cache_switch_to_blog() 替代。
关键要点
- wp_cache_reset() 已弃用,自 WordPress 3.5.0 起推荐使用 wp_cache_switch_to_blog() 来处理博客切换时的缓存准备。
- 该函数重置全局缓存对象 $wp_object_cache 的缓存键,调用 WP_Object_Cache::reset() 方法。
- 在单元测试中清除缓存可考虑使用 wp_cache_init(),但因其性能开销高,不建议在非测试环境中使用。
- 相关函数包括 WP_Object_Cache::reset() 和 _deprecated_function()。
注意事项
避免在生产环境中使用 wp_cache_reset(),因为它已被标记为弃用,可能导致兼容性问题或性能下降。
原文内容
Resets internal cache keys and structures.
Description
If the cache back end uses global blog or site IDs as part of its cache keys, this function instructs the back end to reset those keys and perform any cleanup since blog or site IDs have changed since cache init.
This function is deprecated. Use wp_cache_switch_to_blog() instead of this function when preparing the cache for a blog switch. For clearing the cache during unit tests, consider using wp_cache_init() . wp_cache_init() is not recommended outside of unit tests as the performance penalty for using it is high.
See also
Source
function wp_cache_reset() {
_deprecated_function( __FUNCTION__, '3.5.0', 'wp_cache_switch_to_blog()' );
global $wp_object_cache;
$wp_object_cache->reset();
}
Changelog
| Version | Description |
|---|---|
| 3.5.0 | Deprecated. Use wp_cache_switch_to_blog() |
| 3.0.0 | Introduced. |