From 6b5849b207b2b8e37dbebed7390ed12a140f8a0f Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Fri, 20 Jul 2018 22:54:22 +0300 Subject: [PATCH] Added `MediaTrait::getMediaCache()` to allow custom caching --- CHANGELOG.md | 1 + .../Grav/Common/Media/Traits/MediaTrait.php | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 51592ab35..b1550511a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added twig filters for casting values: `|string`, `|int`, `|bool`, `|float`, `|array` 1. [](#improved) * Added `MediaTrait::clearMediaCache()` to allow cache to be cleared + * Added `MediaTrait::getMediaCache()` to allow custom caching 1. [](#bugfix) * Made `|markdown` filter HTML safe diff --git a/system/src/Grav/Common/Media/Traits/MediaTrait.php b/system/src/Grav/Common/Media/Traits/MediaTrait.php index db40d5673..b8ff918cc 100644 --- a/system/src/Grav/Common/Media/Traits/MediaTrait.php +++ b/system/src/Grav/Common/Media/Traits/MediaTrait.php @@ -55,8 +55,7 @@ trait MediaTrait */ public function getMedia() { - /** @var Cache $cache */ - $cache = Grav::instance()['cache']; + $cache = $this->getMediaCache(); if ($this->media === null) { // Use cached media if possible. @@ -79,8 +78,7 @@ trait MediaTrait */ protected function setMedia(MediaCollectionInterface $media) { - /** @var Cache $cache */ - $cache = Grav::instance()['cache']; + $cache = $this->getMediaCache(); $cacheKey = md5('media' . $this->getCacheKey()); $cache->save($cacheKey, $media); @@ -94,13 +92,19 @@ trait MediaTrait */ protected function clearMediaCache() { - /** @var Cache $cache */ - $cache = Grav::instance()['cache']; - + $cache = $this->getMediaCache(); $cacheKey = md5('media' . $this->getCacheKey()); $cache->delete($cacheKey); } + /** + * @return Cache + */ + protected function getMediaCache() + { + return Grav::instance()['cache']; + } + /** * @return string */