modifs.mineures sans commentaires
This commit is contained in:
parent
a66cb5e232
commit
11c761832a
34
.idea/php.xml
generated
34
.idea/php.xml
generated
@ -23,13 +23,18 @@
|
|||||||
<component name="PhpIncludePathManager">
|
<component name="PhpIncludePathManager">
|
||||||
<include_path>
|
<include_path>
|
||||||
<path value="$PROJECT_DIR$/vendor/composer" />
|
<path value="$PROJECT_DIR$/vendor/composer" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/dflydev/dot-access-data" />
|
||||||
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" />
|
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" />
|
||||||
<path value="$PROJECT_DIR$/vendor/ezyang/htmlpurifier" />
|
<path value="$PROJECT_DIR$/vendor/ezyang/htmlpurifier" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/league/commonmark" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/league/config" />
|
||||||
<path value="$PROJECT_DIR$/vendor/maennchen/zipstream-php" />
|
<path value="$PROJECT_DIR$/vendor/maennchen/zipstream-php" />
|
||||||
<path value="$PROJECT_DIR$/vendor/markbaker/complex" />
|
<path value="$PROJECT_DIR$/vendor/markbaker/complex" />
|
||||||
<path value="$PROJECT_DIR$/vendor/markbaker/matrix" />
|
<path value="$PROJECT_DIR$/vendor/markbaker/matrix" />
|
||||||
<path value="$PROJECT_DIR$/vendor/myclabs/deep-copy" />
|
<path value="$PROJECT_DIR$/vendor/myclabs/deep-copy" />
|
||||||
<path value="$PROJECT_DIR$/vendor/myclabs/php-enum" />
|
<path value="$PROJECT_DIR$/vendor/myclabs/php-enum" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/nette/schema" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/nette/utils" />
|
||||||
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" />
|
<path value="$PROJECT_DIR$/vendor/nikic/php-parser" />
|
||||||
<path value="$PROJECT_DIR$/vendor/nulib/base" />
|
<path value="$PROJECT_DIR$/vendor/nulib/base" />
|
||||||
<path value="$PROJECT_DIR$/vendor/nulib/php" />
|
<path value="$PROJECT_DIR$/vendor/nulib/php" />
|
||||||
@ -38,6 +43,7 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/nulib/tests" />
|
<path value="$PROJECT_DIR$/vendor/nulib/tests" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phar-io/manifest" />
|
<path value="$PROJECT_DIR$/vendor/phar-io/manifest" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phar-io/version" />
|
<path value="$PROJECT_DIR$/vendor/phar-io/version" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/phpmailer/phpmailer" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phpoffice/phpspreadsheet" />
|
<path value="$PROJECT_DIR$/vendor/phpoffice/phpspreadsheet" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" />
|
<path value="$PROJECT_DIR$/vendor/phpunit/php-code-coverage" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-file-iterator" />
|
<path value="$PROJECT_DIR$/vendor/phpunit/php-file-iterator" />
|
||||||
@ -45,9 +51,13 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-text-template" />
|
<path value="$PROJECT_DIR$/vendor/phpunit/php-text-template" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" />
|
<path value="$PROJECT_DIR$/vendor/phpunit/php-timer" />
|
||||||
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit" />
|
<path value="$PROJECT_DIR$/vendor/phpunit/phpunit" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/cache" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/container" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" />
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/http-client" />
|
<path value="$PROJECT_DIR$/vendor/psr/http-client" />
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/http-factory" />
|
<path value="$PROJECT_DIR$/vendor/psr/http-factory" />
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/http-message" />
|
<path value="$PROJECT_DIR$/vendor/psr/http-message" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/psr/log" />
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/simple-cache" />
|
<path value="$PROJECT_DIR$/vendor/psr/simple-cache" />
|
||||||
<path value="$PROJECT_DIR$/vendor/sebastian/cli-parser" />
|
<path value="$PROJECT_DIR$/vendor/sebastian/cli-parser" />
|
||||||
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit" />
|
<path value="$PROJECT_DIR$/vendor/sebastian/code-unit" />
|
||||||
@ -65,28 +75,18 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" />
|
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" />
|
||||||
<path value="$PROJECT_DIR$/vendor/sebastian/type" />
|
<path value="$PROJECT_DIR$/vendor/sebastian/type" />
|
||||||
<path value="$PROJECT_DIR$/vendor/sebastian/version" />
|
<path value="$PROJECT_DIR$/vendor/sebastian/version" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/cache" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/cache-contracts" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
|
<path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/expression-language" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
|
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
|
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/service-contracts" />
|
||||||
|
<path value="$PROJECT_DIR$/vendor/symfony/var-exporter" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/yaml" />
|
<path value="$PROJECT_DIR$/vendor/symfony/yaml" />
|
||||||
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" />
|
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" />
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/cache" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/container" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/nette/utils" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/nette/schema" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/log" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/dflydev/dot-access-data" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/cache" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/expression-language" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/service-contracts" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/cache-contracts" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/var-exporter" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/league/config" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/league/commonmark" />
|
|
||||||
<path value="$PROJECT_DIR$/vendor/phpmailer/phpmailer" />
|
|
||||||
</include_path>
|
</include_path>
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
|
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
|
||||||
|
16
src/cache/TODO.md
vendored
16
src/cache/TODO.md
vendored
@ -2,4 +2,20 @@
|
|||||||
|
|
||||||
* [ ] CacheChannel: stocker aussi la clé primaire, ce qui permet de récupérer la donnée correspondante dans la source
|
* [ ] CacheChannel: stocker aussi la clé primaire, ce qui permet de récupérer la donnée correspondante dans la source
|
||||||
|
|
||||||
|
* Cache:
|
||||||
|
* une méthode calcule + stocke la valeur
|
||||||
|
* valeur scalaire: compute() puis écriture dans un fichier cache
|
||||||
|
* valeur itérable: compute() puis enregistre dans un channel
|
||||||
|
* une méthode récupère la valeur
|
||||||
|
* valeur scalaire: lecture du fichier cache
|
||||||
|
* valeur itérable: parcours des valeurs du channel
|
||||||
|
|
||||||
|
ainsi, il faudra peut-être deux classes: DataCache et CursorCache qui
|
||||||
|
implémentent ces deux fonctionnalités
|
||||||
|
* cache::get() utilise DataCache
|
||||||
|
* cache::all() utilise CursorCache
|
||||||
|
|
||||||
|
peut-être qu'on peut garder CacheFile et le fonctionnement ci-dessus est
|
||||||
|
implémenté dans CacheData? à voir
|
||||||
|
|
||||||
-*- coding: utf-8 mode: markdown -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8:noeol:binary
|
-*- coding: utf-8 mode: markdown -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8:noeol:binary
|
16
src/cache/cache.php
vendored
16
src/cache/cache.php
vendored
@ -61,20 +61,20 @@ class cache {
|
|||||||
$cacheId = ["group_id" => $groupId, "id" => $id];
|
$cacheId = ["group_id" => $groupId, "id" => $id];
|
||||||
}
|
}
|
||||||
|
|
||||||
static function get(callable $compute, $dataId=null, ?string $file=null) {
|
static function get($dataId, callable $compute, ?array $params=null) {
|
||||||
self::verifix_id($dataId);
|
self::verifix_id($dataId);
|
||||||
$file ??= "{$dataId["group_id"]}_{$dataId["id"]}";
|
$file = "{$dataId["group_id"]}_{$dataId["id"]}";
|
||||||
$noCache = !self::should_cache($dataId["id"], $dataId["group_id"]);
|
$noCache = !self::should_cache($dataId["id"], $dataId["group_id"]);
|
||||||
return CacheFile::with($compute, $file)->get(null, $noCache);
|
return (new CacheFile($file, $compute, $params))->get(null, $noCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function all(?iterable $rows, $cursorId=null, ?string $file=null): iterable {
|
static function all($cursorId, ?iterable $rows, ?array $params=null): iterable {
|
||||||
self::verifix_id($cursorId);
|
self::verifix_id($cursorId);
|
||||||
$file ??= "{$cursorId["group_id"]}_{$cursorId["id"]}_rows";
|
$file = "{$cursorId["group_id"]}_{$cursorId["id"]}_rows";
|
||||||
$ccursorId = new CacheFile($file, function() use ($rows, $cursorId) {
|
$ccursorId = new CacheFile($file, function() use ($cursorId, $rows) {
|
||||||
CursorChannel::with($cursorId, null)->rechargeAll($rows);
|
CursorChannel::with($cursorId)->rechargeAll($rows);
|
||||||
return $cursorId;
|
return $cursorId;
|
||||||
});
|
}, $params);
|
||||||
$noCache = !self::should_cache($cursorId["id"], $cursorId["group_id"]);
|
$noCache = !self::should_cache($cursorId["id"], $cursorId["group_id"]);
|
||||||
return CursorChannel::with($ccursorId->get(null, $noCache));
|
return CursorChannel::with($ccursorId->get(null, $noCache));
|
||||||
}
|
}
|
||||||
|
56
tests/cache/SourceTest.php
vendored
56
tests/cache/SourceTest.php
vendored
@ -2,19 +2,65 @@
|
|||||||
namespace nulib\cache;
|
namespace nulib\cache;
|
||||||
|
|
||||||
use nulib\db\Capacitor;
|
use nulib\db\Capacitor;
|
||||||
use nulib\db\CapacitorStorage;
|
|
||||||
use nulib\db\sqlite\Sqlite;
|
use nulib\db\sqlite\Sqlite;
|
||||||
use nulib\db\sqlite\SqliteStorage;
|
use nulib\db\sqlite\SqliteStorage;
|
||||||
|
use nulib\output\msg;
|
||||||
|
use nulib\output\std\StdMessenger;
|
||||||
use nulib\tests\TestCase;
|
use nulib\tests\TestCase;
|
||||||
|
use Traversable;
|
||||||
|
|
||||||
class SourceTest extends TestCase {
|
class SourceTest extends TestCase {
|
||||||
function test() {
|
static function setUpBeforeClass(): void {
|
||||||
|
msg::set_messenger_class(StdMessenger::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param Traversable|iterable $dest */
|
||||||
|
protected static function assertSource($dest): void {
|
||||||
|
self::assertSame([
|
||||||
|
["pk" => 1, "s" => null, "i" => null, "b" => null],
|
||||||
|
["pk" => 2, "s" => "false", "i" => 0, "b" => 0],
|
||||||
|
["pk" => 3, "s" => "first", "i" => 1, "b" => 1],
|
||||||
|
["pk" => 4, "s" => "second", "i" => 2, "b" => 1],
|
||||||
|
], iterator_to_array($dest));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testDirect() {
|
||||||
$destStorage = new SqliteStorage(new Sqlite(__DIR__.'/dest.db'));
|
$destStorage = new SqliteStorage(new Sqlite(__DIR__.'/dest.db'));
|
||||||
new Capacitor($destStorage, $channel = new CursorChannel("source"));
|
new Capacitor($destStorage, $dest = new CursorChannel("source"));
|
||||||
|
|
||||||
$sourceDb = new SourceDb();
|
$sourceDb = new SourceDb();
|
||||||
$channel->rechargeAll($sourceDb->all("select * from source"));
|
$dest->rechargeAll($sourceDb->all("select * from source"));
|
||||||
|
|
||||||
self::assertTrue(true);
|
$this->assertSource($dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testCache() {
|
||||||
|
$getSource = function() {
|
||||||
|
$db = new SourceDb();
|
||||||
|
msg::info("query source");
|
||||||
|
yield from $db->all("select * from source");
|
||||||
|
};
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
"duration" => 2,
|
||||||
|
"override_duration" => true,
|
||||||
|
];
|
||||||
|
|
||||||
|
msg::info("initial");
|
||||||
|
cache::nc();
|
||||||
|
$dest = cache::all("source", $getSource(), $params);
|
||||||
|
$this->assertSource($dest);
|
||||||
|
|
||||||
|
msg::info("cached");
|
||||||
|
$dest = cache::all("source", $getSource(), $params);
|
||||||
|
$this->assertSource($dest);
|
||||||
|
|
||||||
|
sleep(4);
|
||||||
|
msg::info("expired");
|
||||||
|
$dest = cache::all("source", $getSource(), $params);
|
||||||
|
$this->assertSource($dest);
|
||||||
|
|
||||||
|
sleep(4);
|
||||||
|
msg::info("end");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
tests/cache/cacheTest.php
vendored
10
tests/cache/cacheTest.php
vendored
@ -31,13 +31,13 @@ class cacheTest extends _TestCase {
|
|||||||
|
|
||||||
function testUsage() {
|
function testUsage() {
|
||||||
msg::section("all");
|
msg::section("all");
|
||||||
$rows = cache::all($this->gendata(),"gendata");
|
$rows = cache::all("gendata", $this->gendata());
|
||||||
$this->_testRows($rows);
|
$this->_testRows($rows);
|
||||||
|
|
||||||
msg::section("get");
|
msg::section("get");
|
||||||
$rows = cache::get(function() {
|
$rows = cache::get("gendata", function () {
|
||||||
return self::DATA;
|
return self::DATA;
|
||||||
},"gendata");
|
});
|
||||||
$this->_testRows($rows);
|
$this->_testRows($rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,11 +45,11 @@ class cacheTest extends _TestCase {
|
|||||||
cache::nc();
|
cache::nc();
|
||||||
|
|
||||||
msg::section("first pass");
|
msg::section("first pass");
|
||||||
$rows = cache::all($this->gendata(),"gendata");
|
$rows = cache::all("gendata", $this->gendata());
|
||||||
$this->_testRows($rows);
|
$this->_testRows($rows);
|
||||||
|
|
||||||
msg::section("second pass");
|
msg::section("second pass");
|
||||||
$rows = cache::all($this->gendata(),"gendata");
|
$rows = cache::all("gendata", $this->gendata());
|
||||||
$this->_testRows($rows);
|
$this->_testRows($rows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user