feat: Implement cache invalidation system for master dashboard
- Added HVAC_Master_Dashboard_Data::clear_cache() static method - Clears all 5 cached metrics when events or user data changes - Added WordPress hooks for automatic cache invalidation: - save_post/delete_post for events and ticket types - user_register/deleted_user for trainer changes - Ensures data consistency while maintaining performance benefits - Cache keys organized under 'hvac_master_dashboard' group Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8faf2791cd
commit
1d299e0c82
2 changed files with 58 additions and 0 deletions
|
|
@ -140,6 +140,12 @@ class HVAC_Community_Events {
|
||||||
// Force correct content on master dashboard
|
// Force correct content on master dashboard
|
||||||
add_filter('the_content', array($this, 'force_master_dashboard_content'), 1);
|
add_filter('the_content', array($this, 'force_master_dashboard_content'), 1);
|
||||||
|
|
||||||
|
// Cache invalidation hooks for master dashboard performance
|
||||||
|
add_action('save_post', array($this, 'clear_master_dashboard_cache'), 10, 1);
|
||||||
|
add_action('delete_post', array($this, 'clear_master_dashboard_cache'), 10, 1);
|
||||||
|
add_action('user_register', array($this, 'clear_master_dashboard_cache_on_user_change'));
|
||||||
|
add_action('deleted_user', array($this, 'clear_master_dashboard_cache_on_user_change'));
|
||||||
|
|
||||||
// Authentication checks - these should eventually move to HVAC_Access_Control
|
// Authentication checks - these should eventually move to HVAC_Access_Control
|
||||||
add_action('template_redirect', array($this, 'check_event_summary_auth'));
|
add_action('template_redirect', array($this, 'check_event_summary_auth'));
|
||||||
add_action('template_redirect', array($this, 'check_email_attendees_auth'));
|
add_action('template_redirect', array($this, 'check_email_attendees_auth'));
|
||||||
|
|
@ -1119,4 +1125,36 @@ class HVAC_Community_Events {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear master dashboard cache when posts are saved/deleted
|
||||||
|
*
|
||||||
|
* @param int $post_id Post ID
|
||||||
|
*/
|
||||||
|
public function clear_master_dashboard_cache($post_id) {
|
||||||
|
$post_type = get_post_type($post_id);
|
||||||
|
|
||||||
|
// Clear cache for event-related post types or ticket types
|
||||||
|
$cache_trigger_types = [
|
||||||
|
'tribe_events',
|
||||||
|
'tec_tc_attendee',
|
||||||
|
'tribe_tpp_attendees',
|
||||||
|
'tribe_rsvp_attendees'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (in_array($post_type, $cache_trigger_types)) {
|
||||||
|
if (class_exists('HVAC_Master_Dashboard_Data')) {
|
||||||
|
HVAC_Master_Dashboard_Data::clear_cache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear master dashboard cache when user data changes
|
||||||
|
*/
|
||||||
|
public function clear_master_dashboard_cache_on_user_change() {
|
||||||
|
if (class_exists('HVAC_Master_Dashboard_Data')) {
|
||||||
|
HVAC_Master_Dashboard_Data::clear_cache();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // End class HVAC_Community_Events
|
} // End class HVAC_Community_Events
|
||||||
|
|
@ -290,6 +290,26 @@ class HVAC_Master_Dashboard_Data {
|
||||||
return $total_revenue;
|
return $total_revenue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all cached master dashboard data
|
||||||
|
* Should be called when events, tickets, or trainer data changes
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function clear_cache() {
|
||||||
|
$cache_keys = [
|
||||||
|
'hvac_master_total_events_count',
|
||||||
|
'hvac_master_upcoming_events_count',
|
||||||
|
'hvac_master_past_events_count',
|
||||||
|
'hvac_master_total_tickets_sold',
|
||||||
|
'hvac_master_total_revenue'
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($cache_keys as $key) {
|
||||||
|
wp_cache_delete($key, 'hvac_master_dashboard');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get trainer statistics - count and individual performance data
|
* Get trainer statistics - count and individual performance data
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue