From b362dd4617d2b65e5661b0bcbebc043859d18336 Mon Sep 17 00:00:00 2001 From: Ricardo Sawir <37329575+sawirricardo@users.noreply.github.com> Date: Mon, 22 Jan 2024 04:26:15 +0700 Subject: [PATCH] Make Sushi Cache Path more customizeable (#112) * Make Sushi Cache Path more customizeable This is useful if we want to change how the cache path generation is handled * bugfix failed tests * bugfix --- src/Sushi.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Sushi.php b/src/Sushi.php index 410f657..95daae2 100644 --- a/src/Sushi.php +++ b/src/Sushi.php @@ -37,13 +37,29 @@ public static function resolveConnection($connection = null) return static::$sushiConnection; } + protected function sushiCachePath() + { + return implode(DIRECTORY_SEPARATOR, [ + $this->sushiCacheDirectory(), + $this->sushiCacheFileName(), + ]); + } + + protected function sushiCacheFileName() + { + return config('sushi.cache-prefix', 'sushi').'-'.Str::kebab(str_replace('\\', '', static::class)).'.sqlite'; + } + + protected function sushiCacheDirectory() + { + return realpath(config('sushi.cache-path', storage_path('framework/cache'))); + } + public static function bootSushi() { $instance = (new static); - $cacheFileName = config('sushi.cache-prefix', 'sushi').'-'.Str::kebab(str_replace('\\', '', static::class)).'.sqlite'; - $cacheDirectory = realpath(config('sushi.cache-path', storage_path('framework/cache'))); - $cachePath = $cacheDirectory.'/'.$cacheFileName; + $cachePath = $instance->sushiCachePath(); $dataPath = $instance->sushiCacheReferencePath(); $states = [ @@ -75,7 +91,7 @@ public static function bootSushi() $states['cache-file-found-and-up-to-date'](); break; - case file_exists($cacheDirectory) && is_writable($cacheDirectory): + case file_exists($instance->sushiCacheDirectory()) && is_writable($instance->sushiCacheDirectory()): $states['cache-file-not-found-or-stale'](); break;