improve cache system

This commit is contained in:
isUnknown 2025-05-26 13:48:04 +02:00
parent ca0ca3b2a2
commit 1064432984
6 changed files with 39 additions and 26 deletions

View file

@ -3,29 +3,32 @@
use adrienpayet\notifications\NotificationsPage;
class ProjectPage extends NotificationsPage {
public function getSteps($refreshCache = false) {
public function getStepsFromCache() {
$apiCache = kirby()->cache('api');
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
if ($refreshCache) {
$steps = [];
foreach ($this->children() as $child) {
try {
$steps[] = $this->createStep($child);
} catch (\Throwable $th) {
//throw $th;
}
$stepsData = $apiCache->get($this->slug() . '_' . 'steps');
if (!$stepsData) {
$steps = $newPage->getRefreshedSteps(true);
refreshProjectStepsCache($project, $steps);
return $steps;
};
return $stepsData;
}
public function getRefreshedSteps() {
// Create steps
$steps = [];
foreach ($this->children() as $child) {
try {
$steps[] = $this->createStep($child);
} catch (\Throwable $th) {
throw new Exception("Can't create step. File " . $th->getFile() . " line " . $th->getLine(), 1);
}
usort($steps, fn($a, $b) => $a['index'] <=> $b['index']);
$apiCache->set($this->slug() . '_' . 'steps', $steps);
return $steps;
} else {
return $stepsData;
}
// Sort steps by their index
usort($steps, fn($a, $b) => $a['index'] <=> $b['index']);
return $steps;
}
private function createStep($child) {