Skip to content

Commit

Permalink
Merge pull request #322 from gacela-project/feat/default-cache-dir
Browse files Browse the repository at this point in the history
Use sys_get_temp_dir as DefaultCacheDir
  • Loading branch information
Chemaclass authored Dec 1, 2024
2 parents 7210a88 + ea747b0 commit a042a1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Framework/ClassResolver/Cache/GacelaFileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class GacelaFileCache

public const DEFAULT_ENABLED_VALUE = false;

public const DEFAULT_DIRECTORY_VALUE = '/.gacela/cache';
public const DEFAULT_DIRECTORY_VALUE = null;

private static ?bool $isEnabled = null;

Expand Down
15 changes: 12 additions & 3 deletions src/Framework/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public function getCacheDir(): string
return $this->cacheDir;
}

$this->cacheDir = getenv('GACELA_CACHE_DIR') ?: $this->getAppRootDir()
. DIRECTORY_SEPARATOR
. ltrim($this->setup->getFileCacheDirectory(), DIRECTORY_SEPARATOR);
$this->cacheDir = getenv('GACELA_CACHE_DIR') ?: $this->getDefaultCacheDir();

return rtrim($this->cacheDir, DIRECTORY_SEPARATOR);
}
Expand Down Expand Up @@ -157,6 +155,17 @@ public function hasKey(string $key): bool
return array_key_exists($key, $this->config);
}

private function getDefaultCacheDir(): string
{
if ($this->setup->getFileCacheDirectory() === '') {
return sys_get_temp_dir();
}

return $this->getAppRootDir()
. DIRECTORY_SEPARATOR
. ltrim($this->setup->getFileCacheDirectory(), DIRECTORY_SEPARATOR);
}

/**
* @return array<string,mixed>
*/
Expand Down

0 comments on commit a042a1b

Please sign in to comment.