Filter: wpd_ai_report_filters_is_transient_enabled
Control whether report data caching (transients) is enabled or disabled.
Description
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.
Location
File: includes/classes/WPD_Report_Filters.php
Method: WPD_Report_Filters::__construct()
Line: ~66
Parameters
| Parameter | Type | Description |
|---|---|---|
| $is_enabled | bool | Whether transient caching is enabled (default: true) |
Return
Type: bool
Description: True to enable caching, false to disable
Example Usage
Disable Caching in Development
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;
}
Disable Caching for Specific Users
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;
}
Conditional Caching Based on Request
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;
}
Disable During Business Hours
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
Debug Mode Override
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;
}
Completely Disable Caching
add_filter( 'wpd_ai_report_filters_is_transient_enabled', '__return_false' );
Best Practices
- Keep caching enabled in production for performance
- Disable caching during development for accurate testing
- Use conditional logic rather than blanket disabling
- Consider performance impact before disabling cache
- Provide users with a “refresh” button instead of disabling cache
Performance Impact
| 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 |
Important Notes
- Disabling cache forces fresh database queries every time
- Large stores may experience slow report loading without cache
- Cache is automatically cleared when new orders are created
- Default cache duration is 1 hour
- This affects ALL reports, not individual report types
When to Disable Caching
Good Reasons:
- Development and debugging
- Testing report calculations
- Real-time dashboards that need second-by-second accuracy
- Troubleshooting data discrepancies
Bad Reasons:
- Reports seem “slow” (caching helps with this!)
- Data updates infrequently (cache auto-clears on new orders)
- You forgot about it (leaving it disabled in production)
Alternative: Clear Cache Manually
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 ) );
Debugging
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;
}
Related Filters
- wpd_ai_report_filters_allowed_keys_for_query_parameter_values – Control report filter parameters
Related Classes
WPD_Report_Filters– Report filtering and caching systemWPD_Report_API– Report data generation