Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Allow separate directory for locks on filestore #46811

Merged
merged 6 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Illuminate/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ protected function createArrayDriver(array $config)
*/
protected function createFileDriver(array $config)
{
return $this->repository(new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null));
return $this->repository(
(new FileStore($this->app['files'], $config['path'], $config['permission'] ?? null))
->setLockDirectory($config['lock_path'] ?? null)
);
}

/**
Expand Down
29 changes: 28 additions & 1 deletion src/Illuminate/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ class FileStore implements Store, LockProvider
*/
protected $directory;

/**
* The file cache lock directory.
*
* @var string|null
*/
protected $lockDirectory;

/**
* Octal representation of the cache file permissions.
*
Expand Down Expand Up @@ -210,7 +217,14 @@ public function forever($key, $value)
*/
public function lock($name, $seconds = 0, $owner = null)
{
return new FileLock($this, $name, $seconds, $owner);
$this->ensureCacheDirectoryExists($this->lockDirectory ?? $this->directory);

return new FileLock(
new static($this->files, $this->lockDirectory ?? $this->directory, $this->filePermission),
$name,
$seconds,
$owner
);
}

/**
Expand Down Expand Up @@ -364,6 +378,19 @@ public function getDirectory()
return $this->directory;
}

/**
* Set the cache directory where locks should be stored.
*
* @param string|null $lockDirectory
* @return $this
*/
public function setLockDirectory($lockDirectory)
{
$this->lockDirectory = $lockDirectory;

return $this;
}

/**
* Get the cache key prefix.
*
Expand Down