mod: fix caching!

This commit is contained in:
Didier Slof 2023-02-02 08:31:50 +01:00
parent 34ed81516b
commit dc5d204cfc
Signed by: didier
GPG key ID: 01E71F18AA4398E5
8 changed files with 42 additions and 7 deletions

View 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]);
}
}

View file

@ -0,0 +1 @@
<img src="{{ $src }}" alt="{{ $alt }}" class="{{ $class }}" width="{{ $width }}" height="{{ $height }}"/>

View file

@ -19,8 +19,7 @@
<div id="showings"> <div id="showings">
@foreach($cinema->showings as $showing) @foreach($cinema->showings as $showing)
<a href="/showing/{{$showing->showing_id}}"> <a href="/showing/{{$showing->showing_id}}">
<img src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster" <x-cache-image src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster" class="poster" width="200px"/>
width="200px">
<div class="details"> <div class="details">
<span>{{$showing->movie->movie_name}}</span><br/> <span>{{$showing->movie->movie_name}}</span><br/>
<span>{{$showing->showing_date}}</span><br/> <span>{{$showing->showing_date}}</span><br/>

View file

@ -18,7 +18,7 @@
<div id="movies"> <div id="movies">
@foreach($genre->movies as $movie) @foreach($genre->movies as $movie)
<a href="/movie/{{$movie->movie_id}}"> <a href="/movie/{{$movie->movie_id}}">
<img src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" width="200px"> <x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
<div class="details"> <div class="details">
<span>{{$movie->movie_name}}</span><br/> <span>{{$movie->movie_name}}</span><br/>
<span>{{$movie->movie_length}} min</span> <span>{{$movie->movie_length}} min</span>

View file

@ -12,7 +12,7 @@
<div id="movies"> <div id="movies">
@foreach($movies as $movie) @foreach($movies as $movie)
<a class="movie" href="{{route('movie', ['id' => $movie->movie_id])}}"> <a class="movie" href="{{route('movie', ['id' => $movie->movie_id])}}">
<img src="{{ $movie->movie_image }}" alt="{{ $movie->movie_name }}"> <x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
<div class="details"> <div class="details">
<h2>{{ $movie->movie_name }}</h2> <h2>{{ $movie->movie_name }}</h2>
<span>{{ $movie->movie_description }}</span> <span>{{ $movie->movie_description }}</span>

View file

@ -6,7 +6,7 @@
<h1>{{$movie->movie_name}}</h1> <h1>{{$movie->movie_name}}</h1>
<hr/> <hr/>
<div id="movie"> <div id="movie">
<img src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" width="200px"> <x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
<div class="details"> <div class="details">
<span>{{$movie->movie_length}} min</span><br/> <span>{{$movie->movie_length}} min</span><br/>
<span>{{$movie->movie_description}}</span> <span>{{$movie->movie_description}}</span>

View file

@ -3,7 +3,7 @@
@section('content') @section('content')
<section> <section>
<h1><img src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster" width="60px"> <h1><x-cache-image src="{{$showing->movie->movie_image}}" alt="{{$showing->movie->movie_name}} Poster" class="poster" width="60px"/>
{{$showing->movie->movie_name}}</h1> {{$showing->movie->movie_name}}</h1>
<hr/> <hr/>
<div id="showing"> <div id="showing">

View file

@ -11,7 +11,7 @@
<div id="movies"> <div id="movies">
@foreach($movies as $movie) @foreach($movies as $movie)
<a href="/manage/movie/{{$movie->movie_id}}"> <a href="/manage/movie/{{$movie->movie_id}}">
<img src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" width="200px"> <x-cache-image src="{{$movie->movie_image}}" alt="{{$movie->movie_name}} Poster" class="poster" width="200px"/>
<div class="details"> <div class="details">
<h3>{{$movie->movie_name}}</h3><br/> <h3>{{$movie->movie_name}}</h3><br/>
<span>{{ Str::limit($movie->movie_description, 500) }}</span><br/> <span>{{ Str::limit($movie->movie_description, 500) }}</span><br/>