Cache images

This commit is contained in:
philipp lang 2020-10-28 23:52:38 +01:00
parent b15a15afbc
commit a345db162a
2 changed files with 10 additions and 2 deletions

View File

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

View File

@ -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);
}
}