From a345db162aa67a80387a1a7e5c57fc79bc888e9b Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 28 Oct 2020 23:52:38 +0100 Subject: [PATCH] Cache images --- classes/TagPresenter.php | 7 +++++-- models/Attachment.php | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/classes/TagPresenter.php b/classes/TagPresenter.php index 16be3bb..aa78373 100644 --- a/classes/TagPresenter.php +++ b/classes/TagPresenter.php @@ -2,6 +2,7 @@ namespace Aweos\Resizer\Classes; +use Cache; use Storage; use Aweos\Resizer\Models\Attachment; use Aweos\Resizer\Models\Setting; @@ -22,7 +23,9 @@ class TagPresenter { } public function cacheOutput() { - return $this->output(); + return Cache::rememberForever('responsive-image-'.$this->attachment->id, function() { + return $this->output(); + }).' '.$this->attrs; } public function output() { @@ -58,7 +61,7 @@ class TagPresenter { 'sizes' => $sizes->implode(', '), 'srcset' => $srcset->implode(', '), 'alt' => $this->attachment->title - ])).' '.$this->attrs; + ])); } private function htmlAttributes($attr) { diff --git a/models/Attachment.php b/models/Attachment.php index c12d31c..a3f1e40 100644 --- a/models/Attachment.php +++ b/models/Attachment.php @@ -2,6 +2,7 @@ use Model; use Storage; +use Cache; /** * Setting Model @@ -65,4 +66,8 @@ class Attachment extends Model public function getUrlAttribute() { return Storage::disk('uploads')->url($this->source->path); } + + public function beforeDelete() { + Cache::forget('responsive-image-'.$this->id); + } }