From a34bad04c324b8df4c269daa1f03d1adf4c7ad4f Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Sat, 4 Oct 2025 13:03:04 +0400 Subject: [PATCH] modifs.mineures sans commentaires --- src/cache/CacheChannel.php | 6 +++--- src/cache/cache.php | 2 +- tests/cache/CacheChannelTest.php | 2 +- tests/cache/SourceDb.php | 22 ++++++++++++++++++++++ tests/cache/SourceTest.php | 20 ++++++++++++++++++++ 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 tests/cache/SourceDb.php create mode 100644 tests/cache/SourceTest.php diff --git a/src/cache/CacheChannel.php b/src/cache/CacheChannel.php index 96b9508..50d214c 100644 --- a/src/cache/CacheChannel.php +++ b/src/cache/CacheChannel.php @@ -12,7 +12,7 @@ class CacheChannel extends CapacitorChannel implements IteratorAggregate { static function with(?iterable $rows=null, $cursorId=null, ?CapacitorStorage $storage=null): self { $storage ??= cache::storage(); $channel = (new static($cursorId))->initStorage($storage); - if ($rows !== null) $channel->build($rows); + if ($rows !== null) $channel->rechargeAll($rows); return $channel; } @@ -97,7 +97,6 @@ class CacheChannel extends CapacitorChannel implements IteratorAggregate { } function chargeAll(?iterable $items, $func=null, ?array $args=null): int { - $this->index = 0; if ($items === null) return 0; $count = 0; if ($func !== null) $func = func::with($func, $args)->bind($this); @@ -107,8 +106,9 @@ class CacheChannel extends CapacitorChannel implements IteratorAggregate { return $count; } - function build(?iterable $items): self { + function rechargeAll(?iterable $items): self { $this->delete(null); + $this->index = 0; $this->chargeAll($items); return $this; } diff --git a/src/cache/cache.php b/src/cache/cache.php index efb2dfd..be65764 100644 --- a/src/cache/cache.php +++ b/src/cache/cache.php @@ -72,7 +72,7 @@ class cache { self::verifix_id($cursorId); $file ??= "{$cursorId["group_id"]}_{$cursorId["id"]}_rows"; $ccursorId = new CacheFile($file, function() use ($rows, $cursorId) { - CacheChannel::with(null, $cursorId)->build($rows); + CacheChannel::with(null, $cursorId)->rechargeAll($rows); return $cursorId; }); $noCache = !self::should_cache($cursorId["id"], $cursorId["group_id"]); diff --git a/tests/cache/CacheChannelTest.php b/tests/cache/CacheChannelTest.php index 2de3842..53fc866 100644 --- a/tests/cache/CacheChannelTest.php +++ b/tests/cache/CacheChannelTest.php @@ -27,7 +27,7 @@ class CacheChannelTest extends _TestCase { const ADD_COLUMNS = [ "a" => "varchar(30)", ]; - })->initStorage(self::$storage)->build(self::DATA); + })->initStorage(self::$storage)->rechargeAll(self::DATA); $count = 0; foreach ($channel as $key => $item) { msg::info("one: $key => {$item["a"]}"); diff --git a/tests/cache/SourceDb.php b/tests/cache/SourceDb.php new file mode 100644 index 0000000..31dc119 --- /dev/null +++ b/tests/cache/SourceDb.php @@ -0,0 +1,22 @@ +exec("insert into source (s, i, b) values (null, null, null)"); + $db->exec("insert into source (s, i, b) values ('false', 0, 0)"); + $db->exec("insert into source (s, i, b) values ('first', 1, 1)"); + $db->exec("insert into source (s, i, b) values ('second', 2, 1)"); + } + + public function __construct() { + parent::__construct(__DIR__."/source.db"); + } +} diff --git a/tests/cache/SourceTest.php b/tests/cache/SourceTest.php new file mode 100644 index 0000000..6431f1a --- /dev/null +++ b/tests/cache/SourceTest.php @@ -0,0 +1,20 @@ +rechargeAll($sourceDb->all("select * from source")); + + self::assertTrue(true); + } +}