WC_Cache_Helper::delete_version_transients
Deprecated since 3.6.0 Adjusted transient usage to include versions within the transient values, making this cleanup obsolete.. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.
When the transient version increases, this is used to remove all past transients to avoid filling the DB.
Note; this only works on transients appended with the transient version, and when object caching is not being used.
Method of the class: WC_Cache_Helper{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$result = WC_Cache_Helper::delete_version_transients( $version );
- $version(string)
- Version of the transient to remove.
Default:''
Changelog
| Since 2.3.10 | Introduced. |
| Deprecated since 3.6.0 | Adjusted transient usage to include versions within the transient values, making this cleanup obsolete. |
WC_Cache_Helper::delete_version_transients() WC Cache Helper::delete version transients code WC 10.7.0
public static function delete_version_transients( $version = '' ) {
if ( ! wp_using_ext_object_cache() && ! empty( $version ) ) {
global $wpdb;
$limit = apply_filters( 'woocommerce_delete_version_transients_limit', 1000 );
if ( ! $limit ) {
return;
}
$affected = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s LIMIT %d;", '\_transient\_%' . $version, $limit ) ); // WPCS: cache ok, db call ok.
// If affected rows is equal to limit, there are more rows to delete. Delete in 30 secs.
if ( $affected === $limit ) {
wp_schedule_single_event( time() + 30, 'delete_version_transients', array( $version ) );
}
}
}