XinTheme Cache 使用文档

开发者钩子与示例

开发者钩子与示例

XinTheme Cache 提供了一组 Action 和 Filter,方便主题或其他插件触发缓存清理、调整缓存行为或记录日志。

常用 Action

钩子用途
xintheme_cache_clear_complete_cache清理完整缓存。
xintheme_cache_clear_site_cache清理当前站点或指定站点缓存。
xintheme_cache_clear_expired_cache清理过期缓存。
xintheme_cache_clear_page_cache_by_post按文章 ID 清理缓存。
xintheme_cache_clear_page_cache_by_url按 URL 清理缓存。

清理指定文章缓存

do_action( 'xintheme_cache_clear_page_cache_by_post', 123 );

清理指定 URL 缓存

do_action( 'xintheme_cache_clear_page_cache_by_url', 'https://www.example.com/about/' );

允许编辑清理缓存

add_filter(
    'xintheme_cache_user_can_clear_cache',
    function ( $can_clear_cache ) {
        return $can_clear_cache || current_user_can( 'edit_posts' );
    }
);

WooCommerce 动态页面绕过缓存

add_filter(
    'xintheme_cache_bypass_cache',
    function ( $bypass_cache ) {
        if (
            function_exists( 'is_cart' ) && is_cart()
            || function_exists( 'is_checkout' ) && is_checkout()
            || function_exists( 'is_account_page' ) && is_account_page()
        ) {
            return true;
        }

        return $bypass_cache;
    }
);
这页内容对你有帮助吗?