Tribe__Cache::data_size_over_packet_size( string|array|object $value )
If NOT using an external object caching system, then check if the size, in bytes, of the data to write to the database would fit into the max_allowed_packet
setting or not.
Contents
Parameters
- $value
-
(string|array|object) (Required) The value to check.
Return
(bool) Whether the data, in its serialized form, would fit into the current database max_allowed_packet
setting or not.
Source
File: src/Tribe/Cache.php
public function data_size_over_packet_size( $value ) { if ( wp_using_ext_object_cache() ) { // We cannot know and that is a concern of the external caching system. return false; } try { $serialized_value = maybe_serialize( $value ); $size = strlen( $serialized_value ); } catch ( Exception $e ) { // The underlying function would run into the same issue, bail and do not set the transient. return true; } /** @var Tribe__Feature_Detection $feature_detection */ $feature_detection = tribe( 'feature-detection' ); // If the size of the string is above 90% of the database `max_allowed_packet` setting, then it should not be written to the db. return $size > ( $feature_detection->get_mysql_max_packet_size() * .9 ); }
Changelog
Version | Description |
---|---|
4.12.14 | Introduced. |