Skip to content

Commit

Permalink
feat(Cache): Invalidate cache, Fixes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Salamek authored Aug 27, 2020
1 parent 800f509 commit 7cd604f
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,20 @@ public function render()
$key = __CLASS__ . $htmlSnippetTranslation->getId();

$tempFile = $this->tempnam->load($key, $htmlSnippetTranslation->getUpdatedAt());

$invalidateLatteCache = false;
if ($tempFile === null) {
$temp = file_get_contents(__DIR__ . '/detail.latte');

$temp = strtr($temp, ['<!--HTML-SNIPPET-->' => $htmlSnippetTranslation->getHtml()]);
$tempFile = $this->tempnam->save($key, $temp, $htmlSnippetTranslation->getUpdatedAt());
$invalidateLatteCache = true;
}

$template->setFile($tempFile);
if ($invalidateLatteCache) {
$latteTmpFile = $template->getLatte()->getCacheFile($template->getFile());
if (is_file($latteTmpFile)) unlink($latteTmpFile);
}
$template->render();
}
}

0 comments on commit 7cd604f

Please sign in to comment.