mod: fix caching!
This commit is contained in:
parent
34ed81516b
commit
dc5d204cfc
8 changed files with 42 additions and 7 deletions
35
app/View/Components/CacheImage.php
Normal file
35
app/View/Components/CacheImage.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
/// Used to cache online images to local storage
|
||||
class CacheImage extends Component
|
||||
{
|
||||
public function __construct(public string $src, public string $alt = '', public string $class = '', public string $width = "", public string $height = "")
|
||||
{
|
||||
$this->src = $src;
|
||||
$this->alt = $alt;
|
||||
$this->class = $class;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
|
||||
$this->handleCache();
|
||||
}
|
||||
|
||||
public function handleCache()
|
||||
{
|
||||
if (!\Cache::has($this->src)) {
|
||||
$image = file_get_contents($this->src);
|
||||
\Cache::put($this->src, $image, 60 * 24 * 7);
|
||||
}
|
||||
return \Cache::get($this->src);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('components.cache-image', ['src' => $this->handleCache(), 'alt' => $this->alt, 'class' => $this->class, 'width' => $this->width, 'height' => $this->height]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue