Skip to content

Commit b577a63

Browse files
committed
Allow to create path on FileSystemCacheEngine if doesn´t exist.
1 parent b40ffeb commit b577a63

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/Factory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public static function createSessionPool(string $prefix = 'cache', int $bufferSi
2929
);
3030
}
3131

32-
public static function createFilePool(string $prefix = 'cache', ?string $path = null, int $bufferSize = 10, ?LoggerInterface $logger = null): CachePool
32+
public static function createFilePool(string $prefix = 'cache', ?string $path = null, int $bufferSize = 10, ?LoggerInterface $logger = null, bool $createPath = false): CachePool
3333
{
3434
return new CachePool(
35-
new FileSystemCacheEngine($prefix, $path, $logger),
35+
new FileSystemCacheEngine($prefix, $path, $logger, $createPath),
3636
$bufferSize
3737
);
3838
}

src/Psr16/FileSystemCacheEngine.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ class FileSystemCacheEngine extends BaseCacheEngine implements CacheLockInterfac
1919
protected ?string $prefix = null;
2020
protected ?string $path = null;
2121

22-
public function __construct(string $prefix = 'cache', ?string $path = null, ?LoggerInterface $logger = null)
22+
public function __construct(string $prefix = 'cache', ?string $path = null, ?LoggerInterface $logger = null, bool $createPath = false)
2323
{
2424
$this->prefix = $prefix;
2525
$this->path = $path ?? sys_get_temp_dir();
26+
if ($createPath && !file_exists($this->path)) {
27+
mkdir($this->path, 0777, true);
28+
}
2629

2730
$this->logger = $logger;
2831
if (is_null($logger)) {

0 commit comments

Comments
 (0)