PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmFormApi.php +43 -1 6.34 → trunk View file →
@@ -35,8 +35,18 @@
35 35 */
36 36 protected $force = false;
37 37
38 38 /**
39 + * The most recent decode of each cache key's payload.
40 + *
41 + * Each entry is array( 'raw' => string, 'decoded' => mixed ). The raw JSON is kept so a reuse
42 + * can be checked against what is stored right now, rather than assumed to still be current.
43 + *
44 + * @var array<string,array>
45 + */
46 + private static $decoded_cache = array();
47 +
48 + /**
39 49 * @since 3.06
40 50 *
41 51 * @param string|null $license The license key.
42 52 *
@@ -338,9 +348,41 @@
338 348 if ( $is_expired && ! $this->is_running() ) {
339 349 return false;
340 350 }
341 351
342 - return json_decode( $cache['value'], true );
352 + return $this->decode_cached( $cache['value'] );
353 + }
354 +
355 + /**
356 + * Decode a cached API payload, reusing the previous decode of an unchanged payload.
357 + *
358 + * The payload runs to tens of kilobytes of JSON, and decoding it costs far more than reading
359 + * the option it came from. That matters because a single form builder page decodes it once per
360 + * upsell it renders. The reuse is keyed on the raw JSON rather than on the cache key, so
361 + * anything that changes what is stored -- a new license, a cleared cache, a fresh API response,
362 + * a test replacing the option -- is picked up on the very next read instead of being masked.
363 + *
364 + * @since 6.35
365 + *
366 + * @param string $value The cached JSON.
367 + *
368 + * @return mixed
369 + */
370 + private function decode_cached( $value ) {
371 + $previous = self::$decoded_cache[ $this->cache_key ] ?? false;
372 +
373 + if ( $previous && $previous['raw'] === $value ) {
374 + return $previous['decoded'];
375 + }
376 +
377 + $decoded = json_decode( $value, true );
378 +
379 + self::$decoded_cache[ $this->cache_key ] = array(
380 + 'raw' => $value,
381 + 'decoded' => $decoded,
382 + );
383 +
384 + return $decoded;
343 385 }
344 386
345 387 /**
346 388 * Get the cache for the network if multisite.