Tribe__Cache::set_chunkable_transient( string $id, mixed $value, int $expiration, string|array $expiration_trigger = '' )

Sets a transient in the database with the knowledge that, if too large to be stored in one DB row, it will be chunked.

The method will redirect to the set_transient function if the site is using object caching.


Parameters

$id

(string) (Required) The transient ID.

$value

(mixed) (Required) The value to store, that could be chunked.

$expiration

(int) (Required) The transient expiration, in seconds.

$expiration_trigger

(string|<span class="array">array) (Optional) The transient expiration trigger(s).

Default value: ''


Top ↑

Return

(bool) Whether the transient, or the transient chunks, have been stored correctly or not.


Top ↑

Source

File: src/Tribe/Cache.php

	public function set_chunkable_transient( $id, $value, $expiration = 0, $expiration_trigger = '' ) {
		$transient = $this->get_id( $id, $expiration_trigger );

		if ( wp_using_ext_object_cache() ) {
			return $this->set_transient( $transient, $value, $expiration );
		}

		$inserted         = [];
		$serialized_value = maybe_serialize( $value );
		$chunk_size       = tribe( 'feature-detection' )->get_mysql_max_packet_size() * 0.9;
		$chunks           = str_split( $serialized_value, $chunk_size );
		foreach ( $chunks as $i => $chunk ) {
			$chunk_transient = $transient . '_' . $i;

			$set = set_transient( $chunk_transient, $chunk, $expiration );

			if ( ! $set ) {
				foreach ( $inserted as $transient_to_delete ) {
					delete_transient( $transient_to_delete );
				}

				return false;
			}

			$inserted[] = $chunk_transient;
		}

		return true;
	}

Top ↑

Changelog

Changelog
Version Description
4.13.3 Introduced.