From 0628c28f66a793dd493992c9b77d7c4fd272c12b Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Mon, 21 Aug 2023 23:01:42 +0100 Subject: [PATCH] Cache: Increases database cache value size Upped from text to medium text. Aligns with modern Laravel default. Fixes #4453 where were reaching the limit of TEXT. --- app/Api/ApiDocsGenerator.php | 14 +++++--- .../2023_08_21_174248_increase_cache_size.php | 32 +++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 database/migrations/2023_08_21_174248_increase_cache_size.php diff --git a/app/Api/ApiDocsGenerator.php b/app/Api/ApiDocsGenerator.php index 3cd33ffa5..bffc38623 100644 --- a/app/Api/ApiDocsGenerator.php +++ b/app/Api/ApiDocsGenerator.php @@ -7,6 +7,7 @@ use Exception; use Illuminate\Contracts\Container\BindingResolutionException; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Route; use Illuminate\Support\Str; use Illuminate\Validation\Rules\Password; @@ -27,13 +28,16 @@ class ApiDocsGenerator { $appVersion = trim(file_get_contents(base_path('version'))); $cacheKey = 'api-docs::' . $appVersion; - if (Cache::has($cacheKey) && config('app.env') === 'production') { - $docs = Cache::get($cacheKey); - } else { - $docs = (new ApiDocsGenerator())->generate(); - Cache::put($cacheKey, $docs, 60 * 24); + $isProduction = config('app.env') === 'production'; + $cacheVal = $isProduction ? Cache::get($cacheKey) : null; + + if (!is_null($cacheVal)) { + return $cacheVal; } + $docs = (new ApiDocsGenerator())->generate(); + Cache::put($cacheKey, $docs, 60 * 24); + return $docs; } diff --git a/database/migrations/2023_08_21_174248_increase_cache_size.php b/database/migrations/2023_08_21_174248_increase_cache_size.php new file mode 100644 index 000000000..865472c2e --- /dev/null +++ b/database/migrations/2023_08_21_174248_increase_cache_size.php @@ -0,0 +1,32 @@ +mediumText('value')->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('cache', function (Blueprint $table) { + $table->text('value')->change(); + }); + } +};