77 lines
1.4 KiB
PHP
Executable File
77 lines
1.4 KiB
PHP
Executable File
#!/usr/bin/php
|
|
<?php
|
|
require __DIR__.'/../vendor/autoload.php';
|
|
|
|
use nulib\cache\CacheData;
|
|
use nulib\cache\CacheFile;
|
|
use nulib\ext\yaml;
|
|
use nulib\os\sh;
|
|
|
|
function show(string $prefix, CacheFile $cache, bool $dumpInfos=true): void {
|
|
Txx("$prefix=", $cache->get());
|
|
if ($dumpInfos) {
|
|
yaml::dump($cache->getInfos());
|
|
}
|
|
}
|
|
|
|
//system("rm -f *.cache .*.cache");
|
|
|
|
$what = [
|
|
//"null",
|
|
"one",
|
|
//"two",
|
|
//"three",
|
|
];
|
|
$duration = 10;
|
|
|
|
if (in_array("null", $what)) {
|
|
$null = new CacheFile("null", [
|
|
"duration" => $duration,
|
|
]);
|
|
show("null", $null);
|
|
}
|
|
|
|
if (in_array("one", $what)) {
|
|
$one = new class("one", [
|
|
"duration" => $duration,
|
|
]) extends CacheFile {
|
|
protected function compute() {
|
|
return 1;
|
|
}
|
|
};
|
|
show("one", $one);
|
|
}
|
|
|
|
if (in_array("two", $what)) {
|
|
$two = new CacheFile("two", [
|
|
"duration" => $duration,
|
|
"data" => new CacheData(function () {
|
|
return 2;
|
|
}),
|
|
]);
|
|
show("two", $two);
|
|
}
|
|
|
|
if (in_array("three", $what)) {
|
|
$data31 = new CacheData(function () {
|
|
return 31;
|
|
}, "data31name");
|
|
|
|
$data32 = new CacheData(function () {
|
|
return 32;
|
|
});
|
|
|
|
$three = new CacheFile("three", [
|
|
"data" => [
|
|
"data31" => $data31,
|
|
$data31, # name=data31name
|
|
"data32" => $data32,
|
|
$data32, # name=""
|
|
],
|
|
]);
|
|
Txx("three.0=", $three->get("data31"));
|
|
Txx("three.1=", $three->get("data31name"));
|
|
Txx("three.2=", $three->get("data32"));
|
|
Txx("three.3=", $three->get(""));
|
|
}
|