From 43f84843aef17ec810a59f52703cd33e32cbd5b2 Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Fri, 23 May 2025 05:02:01 +0400 Subject: [PATCH] =?UTF-8?q?d=C3=A9placer=20dans=20nur-ture?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/src/db/cache/CacheChannel.php | 116 ------------------------------ php/src/db/cache/RowsChannel.php | 51 ------------- php/src/db/cache/cache.php | 37 ---------- 3 files changed, 204 deletions(-) delete mode 100644 php/src/db/cache/CacheChannel.php delete mode 100644 php/src/db/cache/RowsChannel.php delete mode 100644 php/src/db/cache/cache.php diff --git a/php/src/db/cache/CacheChannel.php b/php/src/db/cache/CacheChannel.php deleted file mode 100644 index b1f8619..0000000 --- a/php/src/db/cache/CacheChannel.php +++ /dev/null @@ -1,116 +0,0 @@ - "varchar(64) not null", - "id" => "varchar(64) not null", - "date_start" => "datetime", - "duration_" => "text", - "primary key (group_id, id)", - ]; - - static function get_cache_ids($id): array { - if (is_array($id)) { - $keys = array_keys($id); - if (array_key_exists("group_id", $id)) $groupIdKey = "group_id"; - else $groupIdKey = $keys[1] ?? null; - $groupId = $id[$groupIdKey] ?? ""; - if (array_key_exists("id", $id)) $idKey = "id"; - else $idKey = $keys[0] ?? null; - $id = $id[$idKey] ?? ""; - } else { - $groupId = ""; - } - if (preg_match('/^(.*\\\\)?([^\\\\]+)$/', $groupId, $ms)) { - # si le groupe est une classe, faire un hash du package pour limiter la - # longueur du groupe - [$package, $groupId] = [$ms[1], $ms[2]]; - $package = substr(md5($package), 0, 4); - $groupId = "${groupId}_$package"; - } - return ["group_id" => $groupId, "id" => $id]; - } - - function __construct(?string $duration=null, ?string $name=null) { - parent::__construct($name); - $this->duration = $duration ?? static::DURATION; - $this->includes = static::INCLUDES; - $this->excludes = static::EXCLUDES; - } - - protected string $duration; - - protected ?array $includes; - - protected ?array $excludes; - - function getItemValues($item): ?array { - return cl::merge(self::get_cache_ids($item), [ - "item" => null, - ]); - } - - function onCreate($item, array $values, ?array $alwaysNull, ?string $duration=null): ?array { - $now = new DateTime(); - $duration ??= $this->duration; - return [ - "date_start" => $now, - "duration" => new Delay($duration, $now), - ]; - } - - function onUpdate($item, array $values, array $pvalues, ?string $duration=null): ?array { - $now = new DateTime(); - $duration ??= $this->duration; - return [ - "date_start" => $now, - "duration" => new Delay($duration, $now), - ]; - } - - function shouldUpdate($id, bool $noCache=false): bool { - if ($noCache) return true; - - $cacheIds = self::get_cache_ids($id); - $groupId = $cacheIds["group_id"]; - if ($groupId) { - $includes = $this->includes; - $shouldInclude = $includes !== null && in_array($groupId, $includes); - $excludes = $this->excludes; - $shouldExclude = $excludes !== null && in_array($groupId, $excludes); - if (!$shouldInclude || $shouldExclude) return true; - } - - $found = false; - $expired = false; - $this->each($cacheIds, - function($item, $values) use (&$found, &$expired) { - $found = true; - $expired = $values["duration"]->isElapsed(); - }); - return !$found || $expired; - } - - function setCached($id, ?string $duration=null): void { - $cacheIds = self::get_cache_ids($id); - $this->charge($cacheIds, null, [$duration]); - } - - function resetCached($id) { - $cacheIds = self::get_cache_ids($id); - $this->delete($cacheIds); - } -} diff --git a/php/src/db/cache/RowsChannel.php b/php/src/db/cache/RowsChannel.php deleted file mode 100644 index a3f7055..0000000 --- a/php/src/db/cache/RowsChannel.php +++ /dev/null @@ -1,51 +0,0 @@ - "varchar(128) primary key not null", - "all_values" => "mediumtext", - ]; - - function __construct($id, callable $builder, ?string $duration=null) { - $this->cacheIds = $cacheIds = CacheChannel::get_cache_ids($id); - $this->builder = Closure::fromCallable($builder); - $this->duration = $duration; - $name = "{$cacheIds["group_id"]}-{$cacheIds["id"]}"; - parent::__construct($name); - } - - protected array $cacheIds; - - protected Closure $builder; - - protected ?string $duration = null; - - function getItemValues($item): ?array { - $key = array_keys($item)[0]; - $row = $item[$key]; - return [ - "key" => $key, - "item" => $row, - "all_values" => implode(" ", cl::filter_n(cl::with($row))), - ]; - } - - function getIterator(): Traversable { - $cm = cache::get(); - if ($cm->shouldUpdate($this->cacheIds)) { - $this->capacitor->reset(); - foreach (($this->builder)() as $key => $row) { - $this->charge([$key => $row]); - } - $cm->setCached($this->cacheIds, $this->duration); - } - return $this->discharge(false); - } -} diff --git a/php/src/db/cache/cache.php b/php/src/db/cache/cache.php deleted file mode 100644 index 401fb19..0000000 --- a/php/src/db/cache/cache.php +++ /dev/null @@ -1,37 +0,0 @@ -