38. Caching Considerations | SEO Forge - Rank Higher with AI-Powered SEO
Download Log in

38. Caching Considerations

Developer Guide

Understanding how SEO Forge caching works helps avoid stale data and optimize performance.

Transient-Based Caching

SEO Forge caches expensive operations using WordPress transients. All sitemap transients have a 1-hour TTL. The 404 log uses a 1-week TTL. Content optimization suggestions are cached per-post for 1 hour.

Invalidating Caches After Bulk Operations

php
// After a bulk import or migration, clear all caches
SEOFORGE_Sitemap::instance()->invalidate_cache();
delete_transient( 'seoforge_404_log' );
delete_transient( 'seoforge_broken_links_cache' );

// Clear optimization cache for specific posts
$post_ids = [ 42, 55, 78 ];
foreach ( $post_ids as $pid ) {
    delete_transient( 'seoforge_optimize_' . $pid );
}

Object Caching Compatibility

SEO Forge uses standard WordPress transient APIs, so it is compatible with persistent object caches (Redis, Memcached). When using an object cache:

  • Transients are stored in the object cache instead of the database
  • TTL behavior is handled by the object cache backend
  • No special configuration is needed
php
// Force-clear all SEO Forge transients (works with or without object cache)
global $wpdb;
$wpdb->query(
    "DELETE FROM {$wpdb->options}
     WHERE option_name LIKE '_transient_seoforge_%'
        OR option_name LIKE '_transient_timeout_seoforge_%'"
);

// If using an object cache, also flush the group
if ( function_exists( 'wp_cache_flush_group' ) ) {
    wp_cache_flush_group( 'transient' );
}

Page Cache Compatibility

When using full-page caching (WP Super Cache, W3 Total Cache, LiteSpeed Cache, etc.), A/B testing requires special consideration. The weekly variant rotation happens on wp_head, so you must ensure the page cache respects the variant:

php
// Add a cache-busting constant for A/B testing pages
add_action( 'template_redirect', function () {
    if ( ! is_singular() ) {
        return;
    }

    $enabled = get_post_meta( get_the_ID(), '_seoforge_ab_enabled', true );
    if ( $enabled ) {
        // Tell caching plugins not to cache this page
        if ( ! defined( 'DONOTCACHEPAGE' ) ) {
            define( 'DONOTCACHEPAGE', true );
        }
    }
} );

Forge AI Assistant Online

Hi! I'm the SEO Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs