Temp disabling all caching within a specific function?
-
Hi all,
we have several functions which I start as admin on demand (using GET parameters) which act based on user-meta data.
We have seen lately that, because W3 is active, “old” metadata was used (because metadata uses WP Object caching) which kinda rendered those functions partially useless.
Do you “pay attention” if I simply switch wp_using_ext_object_cache(false) during runtime, is this a solution for WP Object Caching deactivation?
And how to change behaviour of your DB caching? Can I simply override the variable $cache_reject_reason and set it to a value != null, e.g. $wpdb->cache_reject_reason = ‘cronjob’? That should deactivate as well, correct?
I now created a function which disables object cache, sets all constants, adds a dbcan filter and also sets the value of the rejected_reason of the active processor within the DB-CachedQuery instance, what do you think? Is this complete?
function temp_disable_all_w3cache() { # Disable WP Obj Caching ... wp_using_ext_object_cache(false); # Disable W3 Constants (not sure whether they are recognized during runtime) $cons = array( 'DONOTCACHEPAGE', 'DONOTCACHEDB', 'DONOTMINIFY', 'DONOTCDN', 'DONOTCACHCEOBJECT', 'DONOTCACHEPAGE' ); foreach($cons as $c) { if(!defined($c)) define($c, true); } # Add Filter w3tc_dbcache_can_cache_sql add_filter('w3tc_dbcache_can_cache_sql', function() { return 'DONT_CACHE_MY_CRONS'; }); ########## CHANGE CACHE REJECT REASON for DB CACHING... // Create the closure by reference // https://stackoverflow.com/a/17560595/701049 $reader = function & ($object, $property) { $value = & Closure::bind(function & () use ($property) { return $this->$property; }, $object, $object)->__invoke(); return $value; }; global $wpdb; try { $active_processor = & $reader($wpdb, 'active_processor'); # GET property by reference ... to be able to change it $reject_reason = & $reader($active_processor, 'cache_reject_reason'); # GET property by reference ... to be able to change it $reject_reason = 'DOING_CRON'; # Change private property by reference -> modifies original WPDB } catch (Exception $e) {} }Thanks so much
The topic ‘Temp disabling all caching within a specific function?’ is closed to new replies.