PluginProbe
WindPress – Tailwind CSS integration for WordPress / 3.2.89
WindPress – Tailwind CSS integration for WordPress v3.2.89
3.2.89 3.2.88 3.2.87 3.2.86 3.2.85 3.2.84 3.2.83 3.2.82 3.2.81 trunk 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 143 releases
windpress / src / Core / Scanner / ExtractionCache.php

ExtractionCache.php in WindPress – Tailwind CSS integration for WordPress 3.2.89, at src/Core/Scanner/ExtractionCache.php

32 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WindPress\WindPress\Core\Scanner;
5
6 use WIND_PRESS;
7 /**
8 * Reuses deterministic transformations of freshly read source inputs.
9 */
10 class ExtractionCache
11 {
12 private const VERSION = 1;
13 private const TTL = 7 * 24 * 60 * 60;
14 private const MAX_ENTRY_BYTES = 2 * 1024 * 1024;
15 public static function remember(string $namespace, string $identity, array $inputs, callable $extract)
16 {
17 $key = 'windpress_extract_' . hash('sha256', serialize([self::VERSION, WIND_PRESS::VERSION, get_current_blog_id(), get_current_user_id(), $namespace, $identity]));
18 $fingerprint = hash('sha256', serialize($inputs));
19 $cached = get_transient($key);
20 if (is_array($cached) && ($cached['fingerprint'] ?? null) === $fingerprint && array_key_exists('result', $cached)) {
21 return $cached['result'];
22 }
23 $result = $extract();
24 $entry = ['fingerprint' => $fingerprint, 'result' => $result];
25 // Cache storage is optional; the freshly extracted source remains authoritative.
26 if (strlen(serialize($entry)) <= self::MAX_ENTRY_BYTES) {
27 set_transient($key, $entry, self::TTL);
28 }
29 return $result;
30 }
31 }
32