From bb23f6157f17eff5fc7d84c607b656de76b5e231 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Wed, 10 Feb 2016 22:44:54 -0700 Subject: [PATCH] Support content level meta data .. so you can store things in cache alongside content --- system/src/Grav/Common/Page/Page.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/Page/Page.php b/system/src/Grav/Common/Page/Page.php index 99ccd702d..db055d528 100644 --- a/system/src/Grav/Common/Page/Page.php +++ b/system/src/Grav/Common/Page/Page.php @@ -65,6 +65,7 @@ class Page protected $frontmatter; protected $language; protected $content; + protected $content_meta; protected $summary; protected $raw_content; protected $pagination; @@ -516,8 +517,16 @@ class Page // Load cached content /** @var Cache $cache */ $cache = self::getGrav()['cache']; - $cache_id = md5('page' . $this->id()); - $this->content = $cache->fetch($cache_id); + $cache_id = $this->id(); + $content_obj = $cache->fetch($cache_id); + + if (is_array($content_obj)) { + $this->content = $content_obj['content']; + $this->content_meta = $content_obj['content_meta']; + } else { + $this->content = $content_obj; + } + $process_markdown = $this->shouldProcess('markdown'); $process_twig = $this->shouldProcess('twig'); @@ -574,6 +583,17 @@ class Page return $this->content; } + public function addContentMeta($name, $value) + { + $this->content_meta[$name] = $value; + } + + public function getContentMeta() + { + return $this->content_meta; + } + + /** * Process the Markdown content. Uses Parsedown or Parsedown Extra depending on configuration */ @@ -618,8 +638,8 @@ class Page private function cachePageContent() { $cache = self::getGrav()['cache']; - $cache_id = md5('page' . $this->id()); - $cache->save($cache_id, $this->content); + $cache_id = $this->id(); + $cache->save($cache_id, ['content' => $this->content, 'content_meta' => $this->content_meta]); } /**