modifs.mineures sans commentaires

This commit is contained in:
Jephté Clain 2025-10-07 02:00:52 +04:00
parent 95b0263969
commit 810ead58d6
2 changed files with 30 additions and 39 deletions

View File

@ -232,10 +232,8 @@ class CacheFile extends SharedFile {
$this->start = null; $this->start = null;
$this->duration = null; $this->duration = null;
$this->data = null; $this->data = null;
$updateData = true;
} }
if (!$key && !$external) { if (!$key && !$external) {
if ($updateData) {
# calculer la valeur # calculer la valeur
try { try {
if ($source !== null) $data = $source->compute(); if ($source !== null) $data = $source->compute();
@ -246,13 +244,9 @@ class CacheFile extends SharedFile {
# valeur sera finalement mise à jour # valeur sera finalement mise à jour
throw $e; throw $e;
} }
} else {
$data = $this->data;
}
if ($this->shouldCache($data)) $this->data = $data; if ($this->shouldCache($data)) $this->data = $data;
else $this->data = $data = null; else $this->data = $data = null;
} else { } elseif ($source !== null) {
if ($updateData) {
# calculer la valeur # calculer la valeur
try { try {
$data = $source->compute(); $data = $source->compute();
@ -262,9 +256,6 @@ class CacheFile extends SharedFile {
# valeur sera finalement mise à jour # valeur sera finalement mise à jour
throw $e; throw $e;
} }
} else {
$data = $source->load();
}
if ($this->shouldCache($data)) { if ($this->shouldCache($data)) {
$data = $source->save($data); $data = $source->save($data);
} else { } else {
@ -272,10 +263,12 @@ class CacheFile extends SharedFile {
$source->delete(); $source->delete();
$data = null; $data = null;
} }
} else {
$data = null;
} }
} elseif (!$key && !$external) { } elseif (!$key && !$external) {
$data = $this->data; $data = $this->data;
} elseif ($source->exists()) { } elseif ($source !== null && $source->exists()) {
$data = $source->load(); $data = $source->load();
} else { } else {
$data = null; $data = null;

View File

@ -11,16 +11,6 @@ class cacheTest extends _TestCase {
["a" => 1, "b" => 2], ["a" => 1, "b" => 2],
]; ];
function gendata() {
msg::note("gendata");
foreach (self::DATA as $key => $item) {
msg::info("yield $key");
yield $key => $item;
sleep(2);
}
msg::note("fin gendata");
}
function _testRows(iterable $rows, int $expectedCount) { function _testRows(iterable $rows, int $expectedCount) {
$count = 0; $count = 0;
foreach ($rows as $key => $row) { foreach ($rows as $key => $row) {
@ -70,7 +60,15 @@ class cacheTest extends _TestCase {
function testGetGenerator() { function testGetGenerator() {
$this->_testGet("getGenerator", 3, function () { $this->_testGet("getGenerator", 3, function () {
return $this->gendata(); return static function () {
msg::note("gendata");
foreach (self::DATA as $key => $item) {
msg::info("yield $key");
yield $key => $item;
sleep(2);
}
msg::note("fin gendata");
};
}); });
} }