From e4e1c79d1ae163ecc1ac5e4bf20fd70514e58b30 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 12 Aug 2016 13:27:50 +0200 Subject: [PATCH] Fix issue in storing comments cache when cache is enabled #33 --- CHANGELOG.md | 2 ++ comments.php | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f48989..3174a06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ 1. [](#improved) * Added Romanian translation +1. [](#bugfix) + * Fix issue in storing comments cache when cache is enabled [#33](https://github.com/getgrav/grav-plugin-comments/issues/33) # v1.2.1 ## 07/19/2016 diff --git a/comments.php b/comments.php index b3823f1..f8ae6f4 100644 --- a/comments.php +++ b/comments.php @@ -18,7 +18,7 @@ class CommentsPlugin extends Plugin protected $route = 'comments'; protected $enable = false; protected $comments_cache_id; - + /** * @return array */ @@ -92,7 +92,7 @@ class CommentsPlugin extends Plugin public function initializeFrontend() { $this->calculateEnable(); - + if ($this->enable) { $this->enable([ 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], @@ -101,12 +101,14 @@ class CommentsPlugin extends Plugin 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] ]); } - + $cache = $this->grav['cache']; + $uri = $this->grav['uri']; + //init cache id - $this->comments_cache_id = md5('comments-data' . $cache->getKey()); + $this->comments_cache_id = md5('comments-data' . $cache->getKey() . '-' . $uri->url()); } - + /** * Admin side initialization */ @@ -136,7 +138,7 @@ class CommentsPlugin extends Plugin $this->grav['twig']->comments = $comments; $this->grav['twig']->pages = $this->fetchPages(); } - + /** */ public function onPluginsInitialized() @@ -325,7 +327,7 @@ class CommentsPlugin extends Plugin if ($comments = $cache->fetch($this->comments_cache_id)) { return $comments; } - + $lang = $this->grav['language']->getLanguage(); $filename = $lang ? '/' . $lang : ''; $filename .= $this->grav['uri']->path() . '.yaml';