Control whether report data caching (transients) is enabled or disabled.
Alpha Insights caches report data using WordPress transients for performance. This filter allows you to disable caching globally or conditionally, which is useful for development, debugging, or real-time reporting requirements.
File: includes/classes/WPDAI_Report_Filters.php
Method: WPDAI_Report_Filters::__construct()
Line: ~66
| Parameter | Type | Description |
|---|---|---|
| $is_enabled | bool | Whether transient caching is enabled (default: true) |
Type: bool
Description: True to enable caching, false to disable
add_filter( 'wpd_ai_report_filters_is_transient_enabled', 'disable_cache_in_dev' );
function disable_cache_in_dev( $is_enabled )
{
// Disable caching in development environment
if ( defined( 'WP_ENVIRONMENT_TYPE' ) && WP_ENVIRONMENT_TYPE === 'development' )
{
return false;
}
return $is_enabled;
}
add_filter( 'wpd_ai_report_filters_is_transient_enabled', 'disable_cache_for_admins' );
function disable_cache_for_admins( $is_enabled )
{
// Administrators always see fresh data
if ( current_user_can( 'manage_options' ) )
{
return false;
}
return $is_enabled;
}
add_filter( 'wpd_ai_report_filters_is_transient_enabled', 'conditional_caching' );
function conditional_caching( $is_enabled )
{
// Disable cache if force_refresh parameter is set
if ( isset( $_GET['force_refresh'] ) && $_GET['force_refresh'] === 'true' )
{
return false;
}
// Disable cache for real-time reports
if ( isset( $_GET['report_type'] ) && $_GET['report_type'] === 'realtime' )
{
return false;
}
return $is_enabled;
}
add_filter( 'wpd_ai_report_filters_is_transient_enabled', 'disable_cache_business_hours' );
function disable_cache_business_hours( $is_enabled )
{
// Get current hour in store timezone
$current_hour = (int) current_time( 'H' );
// Disable cache during business hours (9 AM - 5 PM) for fresh data
if ( $current_hour >= 9 && $current_hour < 17 )
{
return false;
}
// Enable cache outside business hours
return $is_enabled;
}
add_filter( 'wpd_ai_report_filters_is_transient_enabled', 'debug_mode_no_cache' );
function debug_mode_no_cache( $is_enabled )
{
// Disable caching when WP_DEBUG is enabled
if ( defined( 'WP_DEBUG' ) && WP_DEBUG )
{
return false;
}
return $is_enabled;
}
add_filter( 'wpd_ai_report_filters_is_transient_enabled', '__return_false' );
| Scenario | With Cache | Without Cache |
|---|---|---|
| Small Store (<1,000 orders) | ~0.1s | ~0.5s |
| Medium Store (1,000-10,000 orders) | ~0.2s | ~2-3s |
| Large Store (>10,000 orders) | ~0.3s | ~5-10s |
Instead of disabling cache, you can clear it manually:
// Clear all report caches
delete_transient( 'wpd_ai_report_*' );
// Or clear specific report cache
delete_transient( 'wpd_ai_report_' . md5( $report_key ) );
add_filter( 'wpd_ai_report_filters_is_transient_enabled', 'debug_cache_status' );
function debug_cache_status( $is_enabled )
{
error_log( 'Alpha Insights Report Cache: ' . ( $is_enabled ? 'ENABLED' : 'DISABLED' ) );
return $is_enabled;
}
WPDAI_Report_Filters - Report filtering and caching systemWPDAI_Reporting_API - Report data generation