Caching for markdown
This commit is contained in:
parent
39bab7153a
commit
e517d78bf2
3 changed files with 15 additions and 2 deletions
|
@ -30,6 +30,7 @@ class AntCMS
|
|||
$pageTemplate = str_replace('<!--AntCMS-Debug-->', '<p>Took ' . $elapsed_time . ' seconds to render the page.', $pageTemplate);
|
||||
|
||||
echo $pageTemplate;
|
||||
exit;
|
||||
}
|
||||
|
||||
public function renderException($exceptionCode)
|
||||
|
|
|
@ -9,7 +9,7 @@ class AntKeywords
|
|||
public function generateKeywords($content = '', $count = 15)
|
||||
{
|
||||
$cache = new AntCache();
|
||||
$cacheKey = hash('sha3-512', $content);
|
||||
$cacheKey = hash('sha3-512', $content).'keywords';
|
||||
|
||||
if ($cache->isCached($cacheKey)) {
|
||||
$cachedKeywords = $cache->getCache($cacheKey);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace AntCMS;
|
||||
|
||||
use Michelf\MarkdownExtra;
|
||||
use PDO;
|
||||
use AntCMS\AntCache;
|
||||
|
||||
class AntMarkdown
|
||||
{
|
||||
|
@ -53,6 +53,17 @@ class AntMarkdown
|
|||
|
||||
public static function renderMarkdown($md)
|
||||
{
|
||||
$cache = new AntCache();
|
||||
$cacheKey = hash('sha3-512', $md).'markdown';
|
||||
|
||||
if ($cache->isCached($cacheKey)) {
|
||||
$cachedContent = $cache->getCache($cacheKey);
|
||||
|
||||
if ($cachedContent !== false && !empty($cachedContent)) {
|
||||
return $cachedContent;
|
||||
}
|
||||
}
|
||||
|
||||
$result = MarkdownExtra::defaultTransform($md);
|
||||
$result = preg_replace('/(?:~~)([^~~]*)(?:~~)/', '<s>$1</s>', $result);
|
||||
|
||||
|
@ -60,6 +71,7 @@ class AntMarkdown
|
|||
$result = str_replace($markdown, $unicode, $result);
|
||||
}
|
||||
|
||||
$cache->setCache($cacheKey, $result);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue