46. Caching Considerations | Form Forge - Build Forms with AI in Seconds
Download Log in

46. Caching Considerations

Developer Guide

Form Forge is compatible with page caching plugins, but requires proper configuration to avoid serving stale nonces.

Page Cache Compatibility

Forms use AJAX submission by default, which means the form HTML can be safely cached. However, the nonce token must be refreshed. Form Forge handles this by generating nonces via a separate AJAX call when a cached page loads:

javascript
// If the nonce in the cached HTML is stale, the frontend
// automatically refreshes it via AJAX before first submission
if ( formforgeFront.nonce === '__CACHED__' ) {
    jQuery.post( formforgeFront.ajaxUrl, {
        action: 'formforge_refresh_nonce'
    }, function( response ) {
        formforgeFront.nonce = response.data.nonce;
    } );
}

Object Cache

Analytics stats are cached via WordPress transients for 5 minutes:

php
$cache_key = 'ff_stats_v3_' . $form_id . '_' . $days;
$cached = get_transient( $cache_key );

Excluding Forms from Cache

If you use a full-page cache plugin and encounter nonce issues, exclude form pages:

php
// WP Super Cache
define( 'DONOTCACHEPAGE', true );

// W3 Total Cache — add to page cache exceptions:
// /contact/*
// /apply/*

// LiteSpeed Cache
add_action( 'litespeed_control_set_nocache', function() {
    global $post;
    if ( $post && has_shortcode( $post->post_content, 'formforge' ) ) {
        do_action( 'litespeed_control_set_nocache', 'Form Forge page' );
    }
} );

Clearing Cache After Form Update

php
add_action( 'formforge_form_updated', function( $form_id ) {
    // Clear transient caches
    delete_transient( 'formforge_stats_' . $form_id . '_30' );

    // Clear page cache for pages embedding this form
    if ( function_exists( 'wp_cache_clear_cache' ) ) {
        wp_cache_clear_cache();
    }
} );

Forge AI Assistant Online

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

Just now
Powered by Forge AI · Browse docs