Added MediaTrait::getMediaCache() to allow custom caching

This commit is contained in:
Matias Griese
2018-07-20 22:54:22 +03:00
parent ba0a8c4092
commit 6b5849b207
2 changed files with 12 additions and 7 deletions

View File

@@ -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

View File

@@ -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
*/