From dc5d204cfca480ddfbda036178b8f61184489a5a Mon Sep 17 00:00:00 2001 From: faulty Date: Thu, 2 Feb 2023 08:31:50 +0100 Subject: [PATCH] mod: fix caching! --- app/View/Components/CacheImage.php | 35 +++++++++++++++++++ .../views/components/cache-image.blade.php | 1 + resources/views/main/cinemas/cinema.blade.php | 3 +- resources/views/main/genres/genre.blade.php | 2 +- resources/views/main/movies/index.blade.php | 2 +- resources/views/main/movies/movie.blade.php | 2 +- .../views/main/showings/showing.blade.php | 2 +- resources/views/manage/movies/index.blade.php | 2 +- 8 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 app/View/Components/CacheImage.php create mode 100644 resources/views/components/cache-image.blade.php diff --git a/app/View/Components/CacheImage.php b/app/View/Components/CacheImage.php new file mode 100644 index 0000000..0eaa153 --- /dev/null +++ b/app/View/Components/CacheImage.php @@ -0,0 +1,35 @@ +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]); + } +} diff --git a/resources/views/components/cache-image.blade.php b/resources/views/components/cache-image.blade.php new file mode 100644 index 0000000..487464e --- /dev/null +++ b/resources/views/components/cache-image.blade.php @@ -0,0 +1 @@ +{{ $alt }} diff --git a/resources/views/main/cinemas/cinema.blade.php b/resources/views/main/cinemas/cinema.blade.php index eb94aa5..b415d11 100644 --- a/resources/views/main/cinemas/cinema.blade.php +++ b/resources/views/main/cinemas/cinema.blade.php @@ -19,8 +19,7 @@
@foreach($cinema->showings as $showing) - {{$showing->movie->movie_name}} Poster +
{{$showing->movie->movie_name}}
{{$showing->showing_date}}
diff --git a/resources/views/main/genres/genre.blade.php b/resources/views/main/genres/genre.blade.php index ad0af9c..7969734 100644 --- a/resources/views/main/genres/genre.blade.php +++ b/resources/views/main/genres/genre.blade.php @@ -18,7 +18,7 @@