Skip to content

Commit

Permalink
Added MediaTrait::getMediaCache() to allow custom caching
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Jul 20, 2018
1 parent ba0a8c4 commit 6b5849b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 11 additions & 7 deletions system/src/Grav/Common/Media/Traits/MediaTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public function getMediaUri()
*/
public function getMedia()
{
/** @var Cache $cache */
$cache = Grav::instance()['cache'];
$cache = $this->getMediaCache();

if ($this->media === null) {
// Use cached media if possible.
Expand All @@ -79,8 +78,7 @@ public function getMedia()
*/
protected function setMedia(MediaCollectionInterface $media)
{
/** @var Cache $cache */
$cache = Grav::instance()['cache'];
$cache = $this->getMediaCache();
$cacheKey = md5('media' . $this->getCacheKey());
$cache->save($cacheKey, $media);

Expand All @@ -94,13 +92,19 @@ protected function setMedia(MediaCollectionInterface $media)
*/
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
*/
Expand Down

0 comments on commit 6b5849b

Please sign in to comment.