[wp-trac] [WordPress Trac] #61467: Inconsistent cache handling for network (site) meta

WordPress Trac noreply at wordpress.org
Thu Jun 20 11:54:26 UTC 2024


#61467: Inconsistent cache handling for network (site) meta
-------------------------------------------+-------------------------------
 Reporter:  xParham                        |       Owner:  (none)
     Type:  defect (bug)                   |      Status:  new
 Priority:  normal                         |   Milestone:  Awaiting Review
Component:  Cache API                      |     Version:
 Severity:  major                          |  Resolution:
 Keywords:  has-testing-info dev-feedback  |     Focuses:  multisite,
                                           |  performance
-------------------------------------------+-------------------------------

Comment (by narenin):

 Hi,

 It could be like this.

 {{{#!php
 <?php
 // Modify update_metadata function
 function update_metadata($meta_type, $object_id, $meta_key, $meta_value) {
     if ($meta_type === 'site') {
         return update_network_option($object_id, $meta_key, $meta_value);
     }

     // Existing code for other meta types...

     // Example of existing metadata handling code:
     // return update_meta($meta_type, $object_id, $meta_key, $meta_value);
 }

 // Modify update_network_option function
 function update_network_option($network_id, $option_name, $newvalue) {
     // Call update_metadata to handle the update
     return update_metadata('site', $network_id, $option_name, $newvalue);
 }

 // Function to synchronize caches
 function sync_network_option_and_meta($network_id, $key, $value) {
     // Update the option
     update_network_option($network_id, $key, $value);

     // Clear both caches to ensure consistency
     wp_cache_delete("$network_id:$key", 'site-options');
     wp_cache_delete($network_id, 'site_meta');
 }

 // Example usage in WP CLI
 wp eval 'sync_network_option_and_meta(1, "mykey", "456");'

 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61467#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list